diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index 53115f099c5..c76a1f74499 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -557,8 +557,11 @@ class AccountBankStatementLine(models.Model): # Fully reconciled moves are just linked to the bank statement total = self.amount + currency = self.currency_id or statement_currency for aml_rec in payment_aml_rec: - total -= aml_rec.debit - aml_rec.credit + balance = aml_rec.amount_currency if aml_rec.currency_id else aml_rec.balance + aml_currency = aml_rec.currency_id or aml_rec.company_currency_id + total -= aml_currency._convert(balance, currency, aml_rec.company_id, aml_rec.date) aml_rec.with_context(check_move_validity=False).write({'statement_line_id': self.id}) counterpart_moves = (counterpart_moves | aml_rec.move_id) if aml_rec.journal_id.post_at_bank_rec and aml_rec.payment_id and aml_rec.move_id.state == 'draft': diff --git a/addons/account/tests/test_reconciliation.py b/addons/account/tests/test_reconciliation.py index 6963017a41a..eab1c9f42fb 100644 --- a/addons/account/tests/test_reconciliation.py +++ b/addons/account/tests/test_reconciliation.py @@ -529,6 +529,14 @@ class TestReconciliation(AccountingTestCase): self.diff_income_account.id: {'debit': 0.0, 'credit': 3.27, 'amount_currency': -5, 'currency_id': self.currency_usd_id}, self.account_rcv.id: {'debit': 0.0, 'credit': 52.33, 'amount_currency': -80, 'currency_id': self.currency_usd_id}, } + + payments = bank_stmt_aml.mapped('payment_id') + # creation and reconciliation of the over-amount statement + # has created an another payment + self.assertEqual(len(payments), 2) + # Check amount of second, automatically created payment + self.assertEqual((payments - payment).amount, 5) + for aml in bank_stmt_aml: line = lines[aml.account_id.id] if type(line) == list: