From 40b890d6e4301794b54eed6a2d0ab86f24661a20 Mon Sep 17 00:00:00 2001 From: Enric Tobella Date: Mon, 17 Jun 2024 21:41:57 +0200 Subject: [PATCH] [IMP] account_reconcile_oca: Fix multicurrency journal management The main idea of this commit is to show the right currency amount --- .../models/account_reconcile_abstract.py | 13 ++--- .../tests/test_bank_account_reconcile.py | 51 +++++++++++++++++++ 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/account_reconcile_oca/models/account_reconcile_abstract.py b/account_reconcile_oca/models/account_reconcile_abstract.py index 02ea9d02..ec53563f 100644 --- a/account_reconcile_oca/models/account_reconcile_abstract.py +++ b/account_reconcile_oca/models/account_reconcile_abstract.py @@ -53,18 +53,15 @@ class AccountReconcileAbstract(models.AbstractModel): if amount < currency_max_amount < 0: amount = currency_max_amount net_amount = max_amount - amount = -amount + currency_amount = -amount original_amount = -original_amount net_amount = -net_amount + amount = amount_currency._convert( + currency_amount, self.company_id.currency_id, self.company_id, date + ) else: amount_currency = line.currency_id - amount = self.company_id.currency_id._convert( - amount, amount_currency, self.company_id, date - ) - currency_amount = amount - amount = amount_currency._convert( - amount, self.company_id.currency_id, self.company_id, date - ) + currency_amount = line.amount_currency vals = { "reference": "account.move.line;%s" % line.id, "id": line.id, diff --git a/account_reconcile_oca/tests/test_bank_account_reconcile.py b/account_reconcile_oca/tests/test_bank_account_reconcile.py index ff1fdfa9..59640479 100644 --- a/account_reconcile_oca/tests/test_bank_account_reconcile.py +++ b/account_reconcile_oca/tests/test_bank_account_reconcile.py @@ -1020,3 +1020,54 @@ class TestReconciliationWidget(TestAccountReconciliationCommon): self.assertTrue(bank_stmt_line.can_reconcile) bank_stmt_line.reconcile_bank_line() self.assertEqual(0, inv1.amount_residual) + + def test_journal_foreign_currency_change(self): + self.env["res.currency.rate"].create( + { + "currency_id": self.env.ref("base.EUR").id, + "name": time.strftime("%Y-07-14"), + "rate": 1.15, + } + ) + bank_stmt = self.acc_bank_stmt_model.create( + { + "company_id": self.env.ref("base.main_company").id, + "journal_id": self.bank_journal_usd.id, + "date": time.strftime("%Y-07-15"), + "name": "test", + } + ) + bank_stmt_line = self.acc_bank_stmt_line_model.create( + { + "name": "testLine", + "journal_id": self.bank_journal_usd.id, + "statement_id": bank_stmt.id, + "amount": 100, + "date": time.strftime("%Y-07-15"), + } + ) + with Form( + bank_stmt_line, + view="account_reconcile_oca.bank_statement_line_form_reconcile_view", + ) as f: + line = f.reconcile_data_info["data"][0] + self.assertEqual( + line["currency_amount"], + 100, + ) + self.env["res.currency.rate"].create( + { + "currency_id": self.env.ref("base.EUR").id, + "name": time.strftime("%Y-07-15"), + "rate": 1.2, + } + ) + with Form( + bank_stmt_line, + view="account_reconcile_oca.bank_statement_line_form_reconcile_view", + ) as f: + line = f.reconcile_data_info["data"][0] + self.assertEqual( + line["currency_amount"], + 100, + )