From 9a16ee5f8ab22e1902b4f5db9841981d3e96a673 Mon Sep 17 00:00:00 2001 From: ced <> Date: Wed, 21 Nov 2007 15:24:39 +0000 Subject: [PATCH] Fix ref in account move line from invoice and some indentations bzr revid: ced-4b6e27000c37b0b778547184721cd48e964a046a --- addons/account/account_move_line.py | 7 +++++-- addons/account/invoice.py | 20 +++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 98bb60fa1c9..a20a81948af 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -70,7 +70,8 @@ class account_move_line(osv.osv): account_move_line \ where \ journal_id=%d and period_id=%d and create_uid=%d and state=%s \ - order by id desc limit 1', (context['journal_id'], context['period_id'], uid, 'draft')) + order by id desc limit 1', + (context['journal_id'], context['period_id'], uid, 'draft')) res = cr.fetchone() move_id = (res and res[0]) or False if not move_id: @@ -82,7 +83,9 @@ class account_move_line(osv.osv): from \ account_move_line \ where \ - journal_id=%d and period_id=%d and create_uid=%d order by id desc', (context['journal_id'], context['period_id'], uid)) + journal_id=%d and period_id=%d and create_uid=%d \ + order by id desc', + (context['journal_id'], context['period_id'], uid)) res = cr.fetchone() data['date'] = res and res[0] or time.strftime('%Y-%m-%d') diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 49a4259ec00..d869ea38ea8 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -508,17 +508,27 @@ class account_invoice(osv.osv): } def action_number(self, cr, uid, ids, *args): - cr.execute('SELECT id, type, number, move_id, reference FROM account_invoice WHERE id IN ('+','.join(map(str,ids))+')') + cr.execute('SELECT id, type, number, move_id, reference ' \ + 'FROM account_invoice ' \ + 'WHERE id IN ('+','.join(map(str,ids))+')') for (id, invtype, number, move_id, reference) in cr.fetchall(): if not number: - number = self.pool.get('ir.sequence').get(cr, uid, 'account.invoice.'+invtype) + number = self.pool.get('ir.sequence').get(cr, uid, + 'account.invoice.' + invtype) if type in ('in_invoice', 'in_refund'): ref = reference else: ref = self._convert_ref(cr, uid, number) - cr.execute('UPDATE account_invoice SET number=%s WHERE id=%d', (number, id)) - cr.execute('UPDATE account_move_line SET ref=%s WHERE move_id=%d and ref is null', (ref, move_id)) - cr.execute('UPDATE account_analytic_line SET ref=%s FROM account_move_line WHERE account_move_line.move_id=%d AND account_analytic_line.move_id=account_move_line.id', (ref, move_id)) + cr.execute('UPDATE account_invoice SET number=%s ' \ + 'WHERE id=%d', (number, id)) + cr.execute('UPDATE account_move_line SET ref=%s ' \ + 'WHERE move_id=%d AND (ref is null OR ref = \'\')', + (ref, move_id)) + cr.execute('UPDATE account_analytic_line SET ref=%s ' \ + 'FROM account_move_line ' \ + 'WHERE account_move_line.move_id = %d ' \ + 'AND account_analytic_line.move_id = account_move_line.id', + (ref, move_id)) return True def action_cancel(self, cr, uid, ids, *args):