From 65ddf755de8d52191634fd06a82995da790eef5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borja=20L=C3=B3pez=20Soil=C3=A1n=20=28Pexego=29?= <> Date: Wed, 7 Jul 2010 19:41:20 +0530 Subject: [PATCH] [FIX] Account : Validation of moves should create relavent account analytic entries lp bug: https://launchpad.net/bugs/582988 fixed bzr revid: jvo@tinyerp.com-20100707141120-1wqscl1r5t8u6thi --- addons/account/account.py | 77 +++++++++++-------- addons/account/account_view.xml | 20 +---- .../wizard/account_journal_select_view.xml | 2 +- 3 files changed, 49 insertions(+), 50 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 4629a306a0b..314e192e186 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1202,9 +1202,11 @@ class account_move(osv.osv): def validate(self, cr, uid, ids, context={}): if context and ('__last_update' in context): del context['__last_update'] - ok = True + + valid_moves = [] #Maintains a list of moves which can be responsible to create analytic entries + for move in self.browse(cr, uid, ids, context): - #unlink analytic lines on move_lines + # Unlink old analytic lines on move_lines for obj_line in move.line_id: for obj in obj_line.analytic_lines: self.pool.get('account.analytic.line').unlink(cr,uid,obj.id) @@ -1213,7 +1215,7 @@ class account_move(osv.osv): amount = 0 line_ids = [] line_draft_ids = [] - company_id=None + company_id = None for line in move.line_id: amount += line.debit - line.credit line_ids.append(line.id) @@ -1230,45 +1232,59 @@ class account_move(osv.osv): raise osv.except_osv(_('Error'), _("""Couldn't create move with currency different from the secondary currency of the account "%s - %s". Clear the secondary currency field of the account definition if you want to accept all currencies.""" % (line.account_id.code, line.account_id.name))) if abs(amount) < 10 ** -4: + # If the move is balanced + # Add to the list of valid moves + # (analytic lines will be created later for valid moves) + valid_moves.append(move) + + # Check whether the move lines are confirmed + if not len(line_draft_ids): continue + # Update the move lines (set them as valid) + self.pool.get('account.move.line').write(cr, uid, line_draft_ids, { 'journal_id': move.journal_id.id, 'period_id': move.period_id.id, 'state': 'valid' }, context, check=False) - todo = [] + account = {} account2 = {} - if journal.type not in ('purchase','sale'): - continue + + if journal.type in ('purchase','sale'): + for line in move.line_id: + code = amount = 0 + key = (line.account_id.id, line.tax_code_id.id) + if key in account2: + code = account2[key][0] + amount = account2[key][1] * (line.debit + line.credit) + elif line.account_id.id in account: + code = account[line.account_id.id][0] + amount = account[line.account_id.id][1] * (line.debit + line.credit) + if (code or amount) and not (line.tax_code_id or line.tax_amount): + self.pool.get('account.move.line').write(cr, uid, [line.id], { + 'tax_code_id': code, + 'tax_amount': amount + }, context, check=False) + elif journal.centralisation: + # If the move is not balanced, it must be centralised... + + # Add to the list of valid moves + # (analytic lines will be created later for valid moves) + valid_moves.append(move) - for line in move.line_id: - code = amount = 0 - key = (line.account_id.id, line.tax_code_id.id) - if key in account2: - code = account2[key][0] - amount = account2[key][1] * (line.debit + line.credit) - elif line.account_id.id in account: - code = account[line.account_id.id][0] - amount = account[line.account_id.id][1] * (line.debit + line.credit) - if (code or amount) and not (line.tax_code_id or line.tax_amount): - self.pool.get('account.move.line').write(cr, uid, [line.id], { - 'tax_code_id': code, - 'tax_amount': amount - }, context, check=False) # - # Compute VAT + # Update the move lines (set them as valid) # - continue - if journal.centralisation: self._centralise(cr, uid, move, 'debit', context=context) self._centralise(cr, uid, move, 'credit', context=context) self.pool.get('account.move.line').write(cr, uid, line_draft_ids, { 'state': 'valid' }, context, check=False) - continue else: + # We can't validate it (it's unbalanced) + # Setting the lines as draft self.pool.get('account.move.line').write(cr, uid, line_ids, { 'journal_id': move.journal_id.id, 'period_id': move.period_id.id, @@ -1276,13 +1292,12 @@ class account_move(osv.osv): #'tax_amount': False, 'state': 'draft' }, context, check=False) - ok = False - if ok: - list_ids = [] - for tmp in move.line_id: - list_ids.append(tmp.id) - self.pool.get('account.move.line').create_analytic_lines(cr, uid, list_ids, context) - return ok + # Create analytic lines for the valid moves + for record in valid_moves: + self.pool.get('account.move.line').create_analytic_lines(cr, uid, [line.id for line in record.line_id], context) + + return len(valid_moves) > 0 + account_move() class account_move_reconcile(osv.osv): diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index c52302cb823..c96fb9fe8c7 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -1194,7 +1194,7 @@ - + Journal Items @@ -2237,22 +2237,6 @@ id="menu_action_account_fiscal_position_form_template" parent="account_template_folder" sequence="20"/> - - Journal Entries - account.move - form - tree,form - - - - - - Journal Items account.move.line diff --git a/addons/account/wizard/account_journal_select_view.xml b/addons/account/wizard/account_journal_select_view.xml index eb081416e89..4fc94ec0d6c 100644 --- a/addons/account/wizard/account_journal_select_view.xml +++ b/addons/account/wizard/account_journal_select_view.xml @@ -8,7 +8,7 @@ form
-