From 0a4404ebcf394d74fc0a54c1616d9a6cdf71add7 Mon Sep 17 00:00:00 2001 From: Saurabh Mishra Date: Thu, 1 Jun 2023 13:12:58 +0000 Subject: [PATCH] [FIX] account: prevent account_move_line singleton error When '_seek_for_lines' returns multiple suspense_line for transaction_amount calculation, then the user will face this issue 'Expected singleton: account.move.line(516, 517)'. Steps to reproduce: - Create a new transaction in Journal (Bank) by Accounting Journal > Bank Reconcilation > Add a Transaction. - While creating a transaction add a partner, amount (amount > 0), Foreign Currency, Amount in currency and then save it. - Go to Journal Entries by Accounting > Journal Entries and then open your recently created journal entry. - Click on reset to draft and then in 'Journal Items' add a line with some credit amount such that total credit and debit should be equal. (Under Account it should be Bank Suspense Account). - Now click on 'Bank Transaction' button in the form view. By following above steps you will be able to reproduce the error. Applying the changes will resolve the issue. sentry-4217912848 closes odoo/odoo#126284 X-original-commit: 12a75a8521f8150c382645215c440d39af4b50aa Signed-off-by: Laurent Smet (las) --- addons/account/i18n/account.pot | 9 +++++++++ .../account/models/account_bank_statement_line.py | 8 ++++++-- .../account/tests/test_account_bank_statement.py | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index 977722a216e..b95682eaac3 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -12346,6 +12346,15 @@ msgid "" "In doing so, you might want to resequence your entries in order to maintain a continuous date-based sequence." msgstr "" +#. module: account +#. odoo-python +#: code:addons/account/models/account_bank_statement_line.py:0 +#, python-format +msgid "" +"%s reached an invalid state regarding its related statement line.\n" +"To be consistent, the journal entry must always have exactly one suspense line." +msgstr "" + #. module: account #. odoo-python #: code:addons/account/models/account_move.py:0 diff --git a/addons/account/models/account_bank_statement_line.py b/addons/account/models/account_bank_statement_line.py index fd46b5afb3f..16c359fdaf3 100644 --- a/addons/account/models/account_bank_statement_line.py +++ b/addons/account/models/account_bank_statement_line.py @@ -680,8 +680,12 @@ class AccountBankStatementLine(models.Model): 'amount': liquidity_lines.balance, }) - if len(suspense_lines) == 1: - + if len(suspense_lines) > 1: + raise UserError(_( + "%s reached an invalid state regarding its related statement line.\n" + "To be consistent, the journal entry must always have exactly one suspense line.", st_line.move_id.display_name + )) + elif len(suspense_lines) == 1: if journal_currency and suspense_lines.currency_id == journal_currency: # The suspense line is expressed in the journal's currency meaning the foreign currency diff --git a/addons/account/tests/test_account_bank_statement.py b/addons/account/tests/test_account_bank_statement.py index b9dfa33e4b2..219e62cfbae 100644 --- a/addons/account/tests/test_account_bank_statement.py +++ b/addons/account/tests/test_account_bank_statement.py @@ -524,6 +524,20 @@ class TestAccountBankStatementLine(AccountTestInvoicingCommon): with self.subTest(params=params): assertAppliedRate(*params) + def test_for_presence_single_suspense_line(self): + statement_line = self.env['account.bank.statement.line'].create({ + 'journal_id': self.bank_journal_3.id, + 'date': '2019-01-01', + 'payment_ref': 'line_1', + 'amount': 0.0, + }) + + with self.assertRaises(UserError): + statement_line.line_ids = [Command.create({ + 'account_id': statement_line.journal_id.suspense_account_id.id, + 'balance': 0.0, + })] + 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