From 2d2fe7f555ce5e866350f9338b5371925b1cbe0d Mon Sep 17 00:00:00 2001 From: Jose Morales Date: Mon, 11 Feb 2019 17:05:36 +0000 Subject: [PATCH] [FIX] account: reconcile over-amount bank statements in foreign currencies When a bank statement reconciles its lines with payment using a foreign currency, there is a mix up of values between the currency set in bank statement and payment against the company currency. Current Behavior Company Currency: MXN Bank Statement Currency: USD Payment Currency: USD Current Rate 0.05130836 1) Generate a bank statement with 990 USD. 2) Generate a payment with 1000 USD. 3) Reconcile the bank statement against the payment. The reconcile process generates a payment with the difference (10 USD) Before this commit, this automatically created payment took an erroneous amount, Taking a currency-converted amount where it should not have It was happening because the reconcile process uses the debit or credit value(Local Currency) against bank statement line amount (Foreign Currency). After this commit, the amount set in the generated payment because of the difference is 10 USD. closed odoo#30623 closes odoo/odoo#30779 --- addons/account/models/account_bank_statement.py | 5 ++++- addons/account/tests/test_reconciliation.py | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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: