[FIX] account, purchase: stacktrace when no currency is selected

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) <wan@odoo.com>
This commit is contained in:
Habib (ayh)
2023-01-25 21:53:44 +01:00
parent 8889a896f3
commit 29cc267fc1
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -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:
+1 -1
View File
@@ -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')