[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
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user