diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 4a68b395d32..3ee86b47e63 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -837,7 +837,8 @@ class AccountMove(models.Model): def _compute_currency_id(self): for invoice in self: currency = ( - invoice.statement_line_id.foreign_currency_id + invoice.currency_id + or invoice.statement_line_id.foreign_currency_id or invoice.journal_id.currency_id or invoice.journal_id.company_id.currency_id ) diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py index 0a5b6ab1944..b209b49c8a7 100644 --- a/addons/account/tests/test_account_move_out_invoice.py +++ b/addons/account/tests/test_account_move_out_invoice.py @@ -3347,3 +3347,38 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon): self.product_a.property_account_income_id.deprecated = True with self.assertRaises(UserError), self.cr.savepoint(): move.action_post() + + def test_change_currency_id(self): + """ + Test that we are able to change currency on invoice, + even when a default currency is set on journal + """ + self.company_data['default_journal_sale'].currency_id = self.company_data['currency'] + move = self.env['account.move'].create({ + 'move_type': 'out_invoice', + 'partner_id': self.partner_a.id, + 'journal_id': self.company_data['default_journal_sale'].id, + 'invoice_line_ids': [ + Command.create({ + 'name': 'My super product.', + 'quantity': 1.0, + 'price_unit': 750.0, + 'account_id': self.product_a.property_account_income_id.id, + 'tax_ids': False, + }) + ], + }) + + self.assertEqual(move.currency_id, self.company_data['currency']) + move.currency_id = self.currency_data['currency'] + self.assertEqual(move.currency_id, self.currency_data['currency']) + self.assertRecordValues(move.line_ids, [ + { + 'debit': 0.0, + 'credit': self.currency_data['currency']._convert(750.0, self.company_data['currency'], self.env.company, fields.Date.today()), + }, + { + 'debit': self.currency_data['currency']._convert(750.0, self.company_data['currency'], self.env.company, fields.Date.today()), + 'credit': 0.0, + }, + ])