From cf35835b8bea974dfbb7589976c8b79d654eb597 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 5 Nov 2018 09:41:38 +0000 Subject: [PATCH] [FIX] account: no account in manual move creation - Activate multi-currency - Create an Journal Entry manually - Create a line Do not fill Account Fill in Amount Currency Fill in Currency A traceback occurs because `line.company_currency_id`. An extra condition `and line.company_currency_id` is not sufficient to have the onchange working properly. Indeed, the related field `company_currency_id` goes through another related field (`company_id`), leading to an empty value in some cases. opw-1904854 closes odoo/odoo#28389 --- addons/account/models/account_move.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 64e62fee91a..526829cd7a8 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -701,7 +701,7 @@ class AccountMoveLine(models.Model): unaffected_earnings_type = self.env.ref("account.data_unaffected_earnings") record.is_unaffected_earnings_line = unaffected_earnings_type == record.account_id.user_type_id - @api.onchange('amount_currency', 'currency_id') + @api.onchange('amount_currency', 'currency_id', 'account_id') def _onchange_amount_currency(self): '''Recompute the debit/credit based on amount_currency/currency_id and date. However, date is a related field on account.move. Then, this onchange will not be triggered @@ -709,9 +709,10 @@ class AccountMoveLine(models.Model): To fix this problem, see _onchange_date method on account.move. ''' for line in self: + company_currency_id = line.account_id.company_id.currency_id amount = line.amount_currency - if line.currency_id and line.currency_id != line.company_currency_id: - amount = line.currency_id._convert(amount, line.company_currency_id, line.company_id, line.date or fields.Date.today()) + if line.currency_id and company_currency_id and line.currency_id != company_currency_id: + amount = line.currency_id._convert(amount, company_currency_id, line.company_id, line.date or fields.Date.today()) line.debit = amount > 0 and amount or 0.0 line.credit = amount < 0 and -amount or 0.0