Merge lp:~openerp-community-committers/openobject-addons/5.0-bugfix-599090 into lp:~openerp-community-committers/openobject-addons/5.0

Status: Needs review
Proposed branch: lp:~openerp-community-committers/openobject-addons/5.0-bugfix-599090
Merge into: lp:~openerp-community-committers/openobject-addons/5.0
Diff against target: 50 lines (+23/-4)
1 file modified
account/account_move_line.py (+23/-4)
To merge this branch: bzr merge lp:~openerp-community-committers/openobject-addons/5.0-bugfix-599090
Reviewer Review Type Date Requested Status
OpenERP Community Committers Pending
Review via email: mp+41375@code.launchpad.net

Description of the change

account.move.line checks some fields are not updated if the line is reconciled or the move is not in draft state. There is a problem, though, that forbids users from removing unreconciled entries of a draft account moves.

When the user wants to remove a couple of lines of a draft move (leaving the move still in valid state), the system will call account.move validate() function. This function calls account.move.line write() for all account move lines of the move, forbiding the removal if there are move lines in reconciled state. The problem is that account.move's validate() function is not necessarily changing any of the forbiden values, it simply ensures they're properly set. As account.move.line's write() function doesn't check if those values are really changing it always raises an exception.

The patch has been in production in several customers for several months now.

To post a comment you must log in.

Unmerged revisions

2881. By Albert Cervera i Areny - http://www.NaN-tic.com

[IMP] account: Be less restrictive in what can be done when the move is reconciled or is not in draft state.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/account_move_line.py'
2--- account/account_move_line.py 2010-11-04 08:15:41 +0000
3+++ account/account_move_line.py 2010-11-19 23:26:54 +0000
4@@ -777,15 +777,14 @@
5 account_obj = self.pool.get('account.account')
6 if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']:
7 raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!'))
8- if update_check:
9- if ('account_id' in vals) or ('journal_id' in vals) or ('period_id' in vals) or ('move_id' in vals) or ('debit' in vals) or ('credit' in vals) or ('date' in vals):
10- self._update_check(cr, uid, ids, context)
11
12 todo_date = None
13 if vals.get('date', False):
14 todo_date = vals['date']
15 del vals['date']
16
17+ needs_check = False
18+
19 for line in self.browse(cr, uid, ids,context=context):
20 ctx = context.copy()
21 if ('journal_id' not in ctx):
22@@ -803,7 +802,27 @@
23 if journal.centralisation:
24 self._check_moves(cr, uid, context=ctx)
25
26-
27+ # Check is only needed if the value of these fields has changed. It is important to check this
28+ # because when removing a couple of lines of a move, the whole move is validated and this means
29+ # that it's not possible to remove unreconciled move lines from a draft move that has reconciled lines.
30+ if 'journal_id' in vals and line.journal_id.id != vals['journal_id']:
31+ needs_check = True
32+ if 'account_id' in vals and line.account_id.id != vals['account_id']:
33+ needs_check = True
34+ if 'period_id' in vals and line.period_id.id != vals['period_id']:
35+ needs_check = True
36+ if 'move_id' in vals and line.move_id.id != vals['move_id']:
37+ needs_check = True
38+ if 'debit' in vals and line.debit != vals['debit']:
39+ needs_check = True
40+ if 'credit' in vals and line.credit != vals['credit']:
41+ needs_check = True
42+ if 'date' in vals and line.date != vals['date']:
43+ needs_check = True
44+
45+ if update_check and needs_check:
46+ self._update_check(cr, uid, ids, context)
47+
48 result = super(account_move_line, self).write(cr, uid, ids, vals, context)
49
50 if check:

Subscribers

People subscribed via source and target branches