From c8d95cfa9547849f1c251de22e3d0b5dcd2ea869 Mon Sep 17 00:00:00 2001 From: qdp Date: Thu, 6 Nov 2008 15:29:10 +0100 Subject: [PATCH] *chnaed bahavior of numbering on account_move. The account_move now gets a number only once it is posted, in the meanwhile the name_get display now '*'+str(account_move.id) *added an overwriting of the function copy on account_move object (to reset state and account move number) *modified views of encoding by move *modified invoice accordingly to latest change of account_move numbering. Cancelling an invoice will keep the account move number it had and will force it the next time it gets validated. bzr revid: qdp@tinyerp.com-20081106142910-8dhs242gi277rt1k --- addons/account/account.py | 29 +++++++++++++++++++++-------- addons/account/account_view.xml | 11 +++++------ addons/account/invoice.py | 10 +++++++--- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index cbab98b01ea..6512a9c1c1a 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -648,7 +648,7 @@ class account_move(osv.osv): data_move = self.pool.get('account.move').browse(cursor,user,ids) for move in data_move: if move.state=='draft': - name = '*' + move.name + name = '*' + str(move.id) else: name = move.name res.append((move.id, name)) @@ -671,7 +671,7 @@ class account_move(osv.osv): return result _columns = { - 'name': fields.char('Entry Name', size=64, required=True), + 'name': fields.char('Entry Number', size=64, required=True), 'ref': fields.char('Ref', size=64), 'period_id': fields.many2one('account.period', 'Period', required=True, states={'posted':[('readonly',True)]}), 'journal_id': fields.many2one('account.journal', 'Journal', required=True, states={'posted':[('readonly',True)]}), @@ -692,6 +692,7 @@ class account_move(osv.osv): ],'Type', readonly=True, select=True, states={'draft':[('readonly',False)]}), } _defaults = { + 'name': lambda *a: '/', 'state': lambda *a: 'draft', 'period_id': _get_period, 'type' : lambda *a : 'journal_voucher', @@ -727,6 +728,17 @@ class account_move(osv.osv): ] def post(self, cr, uid, ids, context=None): if self.validate(cr, uid, ids, context) and len(ids): + for move in self.browse(cr, uid, ids): + if move.name =='/': + new_name = False + journal = move.journal_id + if journal.sequence_id: + new_name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id) + else: + raise osv.except_osv(_('Error'), _('No sequence defined in the journal !')) + if new_name: + self.write(cr, uid, [move.id], {'name':new_name}) + cr.execute('update account_move set state=%s where id in ('+','.join(map(str,ids))+')', ('posted',)) else: raise osv.except_osv(_('Integrity Error !'), _('You can not validate a non balanced entry !')) @@ -772,12 +784,6 @@ class account_move(osv.osv): l[2]['period_id'] = default_period context['period_id'] = default_period - if not 'name' in vals: - journal = self.pool.get('account.journal').browse(cr, uid, context.get('journal_id', vals.get('journal_id', False))) - if journal.sequence_id: - vals['name'] = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id) - else: - raise osv.except_osv(_('Error'), _('No sequence defined in the journal !')) accnt_journal = self.pool.get('account.journal').browse(cr, uid, vals['journal_id']) if 'line_id' in vals: c = context.copy() @@ -788,6 +794,13 @@ class account_move(osv.osv): result = super(account_move, self).create(cr, uid, vals, context) return result + def copy(self, cr, uid, id, default=None, context=None): + if default is None: + default = {} + default = default.copy() + default.update({'state':'draft', 'name':'/',}) + return super(account_move, self).copy(cr, uid, id, default, context) + def unlink(self, cr, uid, ids, context={}, check=True): toremove = [] for move in self.browse(cr, uid, ids, context): diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 6de5754e9b8..5eb03163c51 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -797,7 +797,8 @@ - + + @@ -812,11 +813,9 @@
- + - - @@ -855,8 +854,8 @@ - - + + diff --git a/addons/account/invoice.py b/addons/account/invoice.py index 5c887064f1e..23544989049 100644 --- a/addons/account/invoice.py +++ b/addons/account/invoice.py @@ -191,6 +191,7 @@ class account_invoice(osv.osv): 'move_lines':fields.function(_get_lines , method=True,type='many2many' , relation='account.move.line',string='Move Lines'), 'residual': fields.function(_amount_residual, method=True, digits=(16,2),string='Residual', store=True, help="Remaining amount due."), 'payment_ids': fields.function(_compute_lines, method=True, relation='account.move.line', type="many2many", string='Payments'), + 'move_name': fields.char('Account Move', size=64), } _defaults = { 'type': _get_type, @@ -323,7 +324,7 @@ class account_invoice(osv.osv): if default is None: default = {} default = default.copy() - default.update({'state':'draft', 'number':False, 'move_id':False}) + default.update({'state':'draft', 'number':False, 'move_id':False, 'move_name':False,}) if 'date_invoice' not in default: default['date_invoice'] = False if 'date_due' not in default: @@ -568,8 +569,10 @@ class account_invoice(osv.osv): journal_id = inv.journal_id.id #self._get_journal(cr, uid, {'type': inv['type']}) journal = self.pool.get('account.journal').browse(cr, uid, journal_id) - if journal.sequence_id: + if journal.sequence_id and not inv.move_name: name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id) + else: + name = inv.move_name if journal.centralisation: raise osv.except_osv(_('UserError'), _('Can not create invoice move on centralized journal')) @@ -585,8 +588,9 @@ class account_invoice(osv.osv): for i in line: i[2]['period_id'] = period_id move_id = self.pool.get('account.move').create(cr, uid, move) + new_move_name = self.pool.get('account.move').browse(cr, uid, move_id).name # make the invoice point to that move - self.write(cr, uid, [inv.id], {'move_id': move_id,'period_id':period_id}) + self.write(cr, uid, [inv.id], {'move_id': move_id,'period_id':period_id, 'move_name':new_move_name}) self.pool.get('account.move').post(cr, uid, [move_id]) self._log_event(cr, uid, ids) return True