[FIX] account: keep invoice currency on journal change
Versions:
---------
- 16.0
- saas-16.1
- saas-16.2
- saas-16.3
- saas-16.4
Steps to reproduce:
-------------------
1. install the purchase and account_accountant modules
2. create a purchase order using a non-default currency;
3. create bill;
4. switch to a journal without set currency.
Issue:
------
Currency of bill automatically changes from the one used
by the order to the company default.
Cause:
------
The `account.move` model only looks at bank statements, journal,
and the company default when computing currency, ignoring any
value that might already be present in the invoice:
```
def _compute_currency_id(self):
for invoice in self:
currency = (
invoice.statement_line_id.foreign_currency_id
or invoice.journal_id.currency_id
or invoice.journal_id.company_id.currency_id
)
invoice.currency_id = currency
```
Solution:
---------
Try to retrieve currency from `invoice.currency_id` before
falling back on the company default.
opw-3434518
closes odoo/odoo#133867
X-original-commit: 114f328575000fd31f117c46381441d7ec0bca05
Signed-off-by: Levi Siuzdak (sile) <sile@odoo.com>
Signed-off-by: Levi Siuzdak <sile@odoo.com>
Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
@@ -892,6 +892,7 @@ class AccountMove(models.Model):
|
||||
currency = (
|
||||
invoice.statement_line_id.foreign_currency_id
|
||||
or invoice.journal_id.currency_id
|
||||
or invoice.currency_id
|
||||
or invoice.journal_id.company_id.currency_id
|
||||
)
|
||||
invoice.currency_id = currency
|
||||
|
||||
@@ -2330,3 +2330,41 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon):
|
||||
payment_state=payment_state,
|
||||
):
|
||||
self._assert_payment_move_state(move_type, amount, counterpart_values_list, payment_state)
|
||||
|
||||
def test_onchange_journal_currency(self):
|
||||
"""
|
||||
Ensure invoice currency changes on journal change, iff the journal
|
||||
has a currency_id set.
|
||||
"""
|
||||
|
||||
chf = self.env.ref('base.CHF')
|
||||
eur = self.env.ref('base.EUR')
|
||||
|
||||
journal_gen_exp = self.env['account.journal'].create({
|
||||
'name': 'Expenses (generic)',
|
||||
'type': 'purchase',
|
||||
'code': 'EXPGEN',
|
||||
})
|
||||
journal_swiss_exp = self.env['account.journal'].create({
|
||||
'name': 'Expenses (CHF)',
|
||||
'type': 'purchase',
|
||||
'code': 'EXPCHF',
|
||||
'currency_id': chf.id,
|
||||
})
|
||||
|
||||
self.invoice.currency_id = eur
|
||||
move_form = Form(self.invoice)
|
||||
invoice = move_form.save()
|
||||
self.assertEqual(invoice.currency_id, eur)
|
||||
|
||||
# No change expected with generic journal
|
||||
move_form.journal_id = journal_gen_exp
|
||||
move_form.save()
|
||||
self.assertEqual(invoice.currency_id, eur,
|
||||
"Changing to a journal without set currency shouldn't affect invoice currency")
|
||||
|
||||
# Currency should change
|
||||
move_form.journal_id = journal_swiss_exp
|
||||
move_form.save()
|
||||
self.assertEqual(invoice.currency_id, chf,
|
||||
"Changing to a journal with a set currency should change invoice currency")
|
||||
|
||||
Reference in New Issue
Block a user