diff --git a/account_constraints/account_constraints.py b/account_constraints/account_constraints.py index 8190e9854..419ffcb95 100644 --- a/account_constraints/account_constraints.py +++ b/account_constraints/account_constraints.py @@ -44,9 +44,22 @@ class AccountMove(orm.Model): class AccountMoveLine(orm.Model): _inherit = 'account.move.line' - def _check_invoice_related_move(self, cr, uid, ids, context=None): + def _authorized_reconcile(self, vals): + """ Check if only reconcile_id and/or reconcile_partial_id are altered. We + cannot change other vals, but we should be able to write or unlink those field + (e.g. when you want to manually unreconcile an entry generated by an invoice). + """ + if not vals: + return False + rec_keys = set(["reconcile_id", "reconcile_partial_id"]) + write_keys = set(vals) + return rec_keys.issuperset(write_keys) + + def _check_invoice_related_move(self, cr, uid, ids, vals=None, context=None): for line in self.browse(cr, uid, ids, context=context): if line.invoice: + if self._authorized_reconcile(vals): + return True err_msg = (_('Invoice name (id): %s (%s)') % (line.invoice.name, line.invoice.id)) raise osv.except_osv( @@ -55,9 +68,11 @@ class AccountMoveLine(orm.Model): 'change the related invoice directly.\n%s.') % err_msg) return True - def _check_statement_related_move(self, cr, uid, ids, context=None): + def _check_statement_related_move(self, cr, uid, ids, vals=None, context=None): for line in self.browse(cr, uid, ids, context=context): if line.statement_id: + if self._authorized_reconcile(vals): + return True err_msg = (_('Bank statement name (id): %s (%s)') % (line.statement_id.name, line.statement_id.id)) raise osv.except_osv( @@ -71,6 +86,7 @@ class AccountMoveLine(orm.Model): - Is the move related to an invoice - Is the move related to a bank statement + - Is other values than reconcile_partial_id and/or reconcile_id modified In that case, we forbid the move to be deleted even if draft. We should never delete directly a move line related or generated by @@ -89,6 +105,7 @@ class AccountMoveLine(orm.Model): - Is the move related to an invoice - Is the move related to a bank statement + - Is other values than reconcile_partial_id and/or reconcile_id modified In that case, we forbid the move to be modified even if draft. We should never update directly a move line related or generated @@ -98,8 +115,8 @@ class AccountMoveLine(orm.Model): if context is None: context = {} if not context.get('from_parent_object', False): - self._check_invoice_related_move(cr, uid, ids, context=context) - self._check_statement_related_move(cr, uid, ids, context=context) + self._check_invoice_related_move(cr, uid, ids, vals, context=context) + self._check_statement_related_move(cr, uid, ids, vals, context=context) return super(AccountMoveLine, self).write(cr, uid, ids, vals, context=context, check=check, update_check=update_check)