From 0a2d73e738a3be217f23ce6744463b8fbc9f0f95 Mon Sep 17 00:00:00 2001 From: Laurent Smet Date: Thu, 28 Jan 2021 12:18:52 +0000 Subject: [PATCH] [FIX] account: Fix 'is_reconciled' flag for zero-amount statement line When the suspense account is not reconcilable, 'suspense_lines.reconciled' always gives 'False' leading to a not reconciled statement line. closes odoo/odoo#65290 X-original-commit: 73ddcfbcc58b7a6542ced4bd8b20dd67c9f446ee Signed-off-by: oco-odoo --- .../account/models/account_bank_statement.py | 26 +++++++++---------- .../tests/test_account_bank_statement.py | 20 ++++++++++++++ 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 698ba5c4e3a..8ae5aef3cca 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -785,19 +785,6 @@ class AccountBankStatementLine(models.Model): for st_line in self: liquidity_lines, suspense_lines, other_lines = st_line._seek_for_lines() - # Compute is_reconciled - if not st_line.id: - # New record: The journal items are not yet there. - st_line.is_reconciled = False - elif suspense_lines: - # In case of the statement line comes from an older version, it could have a residual amount of zero. - st_line.is_reconciled = all(suspense_line.reconciled for suspense_line in suspense_lines) - elif st_line.currency_id.is_zero(st_line.amount): - st_line.is_reconciled = True - else: - # The journal entry seems reconciled. - st_line.is_reconciled = True - # Compute residual amount if st_line.to_check: st_line.amount_residual = -st_line.amount_currency if st_line.foreign_currency_id else -st_line.amount @@ -806,6 +793,19 @@ class AccountBankStatementLine(models.Model): else: st_line.amount_residual = sum(suspense_lines.mapped('amount_currency')) + # Compute is_reconciled + if not st_line.id: + # New record: The journal items are not yet there. + st_line.is_reconciled = False + elif suspense_lines: + # In case of the statement line comes from an older version, it could have a residual amount of zero. + st_line.is_reconciled = suspense_lines.currency_id.is_zero(st_line.amount_residual) + elif st_line.currency_id.is_zero(st_line.amount): + st_line.is_reconciled = True + else: + # The journal entry seems reconciled. + st_line.is_reconciled = True + # ------------------------------------------------------------------------- # CONSTRAINT METHODS # ------------------------------------------------------------------------- diff --git a/addons/account/tests/test_account_bank_statement.py b/addons/account/tests/test_account_bank_statement.py index c582a6d1dc3..8d3ba4983e0 100644 --- a/addons/account/tests/test_account_bank_statement.py +++ b/addons/account/tests/test_account_bank_statement.py @@ -1549,3 +1549,23 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon): {'amount_currency': 226.04, 'debit': 193.22, 'credit': 0.0}, {'amount_currency': -7767.70, 'debit': 0.0, 'credit': 6640.19}, ]) + + def test_zero_amount_statement_line(self): + ''' Ensure the statement line is directly marked as reconciled when having an amount of zero. ''' + self.company_data['company'].account_journal_suspense_account_id.reconcile = False + + statement = self.env['account.bank.statement'].with_context(skip_check_amounts_currencies=True).create({ + 'name': 'test_statement', + 'date': '2017-01-01', + 'journal_id': self.bank_journal_2.id, + 'line_ids': [ + (0, 0, { + 'date': '2019-01-01', + 'payment_ref': "Happy new year", + 'amount': 0.0, + }), + ], + }) + statement_line = statement.line_ids + + self.assertRecordValues(statement_line, [{'is_reconciled': True, 'amount_residual': 0.0}])