From 1ce9dece80f1a23c177749d3072e1daf4aafbc53 Mon Sep 17 00:00:00 2001 From: "Habib (ayh)" Date: Thu, 25 May 2023 08:41:39 +0000 Subject: [PATCH] [IMP] account: compute foreign amount on bank transactions With this commit, we improve the usability of foreign bank transactions. When capturing a new bank transaction (account.bank.statement.line) - when capturing a new transaction we compute the amount currency based on the transaction date, amount in journal/company currency, and foreign currency - when the foreign currency is removed, the amount_currency is cleared Task-3338560 Task-3338532 closes odoo/odoo#122595 X-original-commit: 737c7d26c415b5a136635ef3e4d33d086961c4da Related: odoo/enterprise#41532 Signed-off-by: Laurent Smet --- .../account/models/account_bank_statement_line.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/addons/account/models/account_bank_statement_line.py b/addons/account/models/account_bank_statement_line.py index 735c845bf39..7be0d32b879 100644 --- a/addons/account/models/account_bank_statement_line.py +++ b/addons/account/models/account_bank_statement_line.py @@ -94,6 +94,7 @@ class AccountBankStatementLine(models.Model): help="The optional other currency if it is a multi-currency entry.", ) amount_currency = fields.Monetary( + compute='_compute_amount_currency', store=True, readonly=False, string="Amount in Currency", currency_field='foreign_currency_id', help="The amount expressed in an optional other currency if it is a multi-currency entry.", @@ -147,6 +148,19 @@ class AccountBankStatementLine(models.Model): # COMPUTE METHODS # ------------------------------------------------------------------------- + @api.depends('foreign_currency_id', 'date', 'amount', 'company_id') + def _compute_amount_currency(self): + for st_line in self: + if not st_line.foreign_currency_id or not st_line.date: + st_line.amount_currency = False + else: + st_line.amount_currency = st_line.currency_id._convert( + from_amount=st_line.amount, + to_currency=st_line.foreign_currency_id, + company=st_line.company_id, + date=st_line.date, + ) + @api.depends('journal_id.currency_id') def _compute_currency_id(self): for st_line in self: