[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) <las@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user