mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[FIX] constraint prevent to reconcile a draft move line
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user