From 3d1c192da95c43dc37eb2b010154037a2960eed2 Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Wed, 13 Nov 2019 11:54:00 +0000 Subject: [PATCH] [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 --- addons/account/models/account_move.py | 2 ++ .../account/tests/test_account_move_entry.py | 21 +++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 0fd073d0138..368abd3e5d7 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -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') diff --git a/addons/account/tests/test_account_move_entry.py b/addons/account/tests/test_account_move_entry.py index b1de56bcf71..cdff247edec 100644 --- a/addons/account/tests/test_account_move_entry.py +++ b/addons/account/tests/test_account_move_entry.py @@ -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. '''