From 29cc267fc15fab94c679a4b5a5bb0eb9fb12787f Mon Sep 17 00:00:00 2001 From: "Habib (ayh)" Date: Wed, 25 Jan 2023 11:08:44 +0000 Subject: [PATCH] [FIX] account, purchase: stacktrace when no currency is selected MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tax totals computation requires a currency to be provided. When a user removes the currency deliberately and tries to add a line, an uncaught error is thrown. The currency_id is required, and the user will not be able to save the move anyway. To reproduce: New Invoice or Purchase Clear the currency field Add a line Stack Trace After this PR: tax totals are computed based on the journal currency or company currency when not available No task, discovered thanks to #110920 closes odoo/odoo#111021 X-original-commit: f74f9bc04ed8f18746eb509f3c8dc598b1618230 Signed-off-by: William André (wan) --- addons/account/models/account_move.py | 2 +- addons/purchase/models/purchase.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 93adfb1fab7..a899ddcc5a7 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1133,7 +1133,7 @@ class AccountMove(models.Model): kwargs = { 'base_lines': base_line_values_list, - 'currency': move.currency_id, + 'currency': move.currency_id or move.journal_id.currency_id or move.journal_id.company_id.currency_id, } if move.id: diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index e1468fc3ba0..6122f85b035 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -194,7 +194,7 @@ class PurchaseOrder(models.Model): order_lines = order.order_line.filtered(lambda x: not x.display_type) order.tax_totals = self.env['account.tax']._prepare_tax_totals( [x._convert_to_tax_base_line_dict() for x in order_lines], - order.currency_id, + order.currency_id or order.company_id.currency_id, ) @api.depends('company_id.account_fiscal_country_id', 'fiscal_position_id.country_id', 'fiscal_position_id.foreign_vat')