From 58e4d3f8b7322f2c5a6c5eabad4a34af758cfbf9 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 4 Feb 2013 10:01:09 +0100 Subject: [PATCH 1/4] [FIX] constraint prevent to reconcile a draft move line --- account_constraints/account_constraints.py | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/account_constraints/account_constraints.py b/account_constraints/account_constraints.py index 8190e9854..5228c317e 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 value are altered" + if not vals: + return False + rec_keys = set(["reconcile_id", "reconcile_partial_id"]) + write_keys = set(vals.keys()) + if (rec_keys >= write_keys): + return True + return False + + + 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 + - Only pure reconcile are allowed 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 + - Only pure reconcile are allowed 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) From ff6531f70845810060996516da5b51309d5da761 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 4 Feb 2013 10:35:51 +0100 Subject: [PATCH 2/4] [FIX] line carriage --- account_constraints/account_constraints.py | 1 - 1 file changed, 1 deletion(-) diff --git a/account_constraints/account_constraints.py b/account_constraints/account_constraints.py index 5228c317e..42637d1cc 100644 --- a/account_constraints/account_constraints.py +++ b/account_constraints/account_constraints.py @@ -54,7 +54,6 @@ class AccountMoveLine(orm.Model): return True return False - 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: From 74d0352159218280af6e8b4f90742ee37e8e314c Mon Sep 17 00:00:00 2001 From: Joel Grand-Guillaume Date: Mon, 4 Feb 2013 11:55:49 +0100 Subject: [PATCH 3/4] [DOC] Little changes in the descrption of the doc strings. --- account_constraints/account_constraints.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/account_constraints/account_constraints.py b/account_constraints/account_constraints.py index 42637d1cc..114ea389e 100644 --- a/account_constraints/account_constraints.py +++ b/account_constraints/account_constraints.py @@ -45,7 +45,10 @@ class AccountMoveLine(orm.Model): _inherit = 'account.move.line' def _authorized_reconcile(self, vals): - "check if only reconcile value are altered" + """ 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"]) @@ -85,7 +88,7 @@ class AccountMoveLine(orm.Model): - Is the move related to an invoice - Is the move related to a bank statement - - Only pure reconcile are allowed + - 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 @@ -104,7 +107,7 @@ class AccountMoveLine(orm.Model): - Is the move related to an invoice - Is the move related to a bank statement - - Only pure reconcile are allowed + - 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 From a5a1fec4daa7a230c6698494f8e71bf644bc6a98 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Wed, 6 Feb 2013 10:42:14 +0100 Subject: [PATCH 4/4] [REF] account_constraint: clearer set usage --- account_constraints/account_constraints.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/account_constraints/account_constraints.py b/account_constraints/account_constraints.py index 114ea389e..419ffcb95 100644 --- a/account_constraints/account_constraints.py +++ b/account_constraints/account_constraints.py @@ -52,10 +52,8 @@ class AccountMoveLine(orm.Model): if not vals: return False rec_keys = set(["reconcile_id", "reconcile_partial_id"]) - write_keys = set(vals.keys()) - if (rec_keys >= write_keys): - return True - return False + 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):