diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 73e5728b710..1c9bf7bc945 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -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 diff --git a/addons/account/tests/test_account_move_in_invoice.py b/addons/account/tests/test_account_move_in_invoice.py index e437e328960..7cc96e4f648 100644 --- a/addons/account/tests/test_account_move_in_invoice.py +++ b/addons/account/tests/test_account_move_in_invoice.py @@ -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")