[FIX] account: Fix checking about the reconciliation

There is a constrains preventing writing debit/credit on an already
reconciled journal item. However, this constraint isn't aware about
monetary fields and then, was raising an error when writing amount
like 1.000001 on a debit of 1.0.

closes odoo/odoo#40214

X-original-commit: 7599758494198e64b5b391dbecdfe30baa01e50b
Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
This commit is contained in:
Laurent Smet
2019-11-13 15:24:39 +00:00
committed by fw-bot
parent 5796441784
commit 3d1c192da9
2 changed files with 14 additions and 9 deletions
+2
View File
@@ -3131,6 +3131,8 @@ class AccountMoveLine(models.Model):
current_ids = set(line[field_name].ids)
after_write_ids = set(r['id'] for r in line.resolve_2many_commands(field_name, vals[field_name], fields=['id']))
return current_ids != after_write_ids
if field.type == 'monetary' and line[field.currency_field]:
return not line[field.currency_field].is_zero(line[field_name] - vals[field_name])
return line[field_name] != vals[field_name]
ACCOUNTING_FIELDS = ('debit', 'credit', 'amount_currency')
@@ -278,10 +278,8 @@ class TestAccountMove(AccountTestInvoicingCommon):
(lines[0] + lines[2]).reconcile()
draft_moves.flush()
self.cr.execute('SAVEPOINT test_misc_draft_reconciled_entries_1')
with self.assertRaises(UserError):
# You can't write something impacting the reconciliation on an already reconciled line.
with self.assertRaises(UserError), self.cr.savepoint():
draft_moves[0].write({
'line_ids': [
(1, lines[1].id, {'credit': lines[1].credit + 100.0}),
@@ -289,12 +287,17 @@ class TestAccountMove(AccountTestInvoicingCommon):
]
})
with self.assertRaises(UserError):
draft_moves.unlink()
# The write must not raise anything because the rounding of the monetary field should ignore such tiny amount.
draft_moves[0].write({
'line_ids': [
(1, lines[1].id, {'credit': lines[1].credit + 0.0000001}),
(1, lines[2].id, {'debit': lines[2].debit + 0.0000001}),
]
})
draft_moves.flush()
draft_moves.invalidate_cache()
self.cr.execute('ROLLBACK TO SAVEPOINT test_misc_draft_reconciled_entries_1')
# You can't unlink an already reconciled line.
with self.assertRaises(UserError), self.cr.savepoint():
draft_moves.unlink()
def test_misc_unique_sequence_number(self):
''' Ensure two journal entries can't share the same name when using the same sequence. '''