diff --git a/addons/sale/tests/test_sale_report.py b/addons/sale/tests/test_sale_report.py index e02c1860946..3792b759ac6 100644 --- a/addons/sale/tests/test_sale_report.py +++ b/addons/sale/tests/test_sale_report.py @@ -21,6 +21,9 @@ class TestSaleReportCurrencyRate(SaleCommon): cls.eur_cmp = cls.env['res.company'].create({ 'name': 'EUR Company', 'currency_id': cls.env.ref('base.EUR').id, }) + # The test requires the main company to be in USD so that the currency of the products + # shared between companies is USD + cls._use_currency('USD') def test_sale_report_foreign_currency(self): """ diff --git a/odoo/addons/base/tests/common.py b/odoo/addons/base/tests/common.py index 97c8b1f4f00..c2c7b6ea409 100644 --- a/odoo/addons/base/tests/common.py +++ b/odoo/addons/base/tests/common.py @@ -40,6 +40,16 @@ class BaseCommon(TransactionCase): currency.action_unarchive() return currency + @classmethod + def _use_currency(cls, currency_code): + # Enforce constant currency + currency = cls._enable_currency(currency_code) + if not cls.env.company.currency_id == currency: + cls.env.transaction.cache.set(cls.env.company, type(cls.env.company).currency_id, currency.id, dirty=True) + # this is equivalent to cls.env.company.currency_id = currency but without triggering buisness code checks. + # The value is added in cache, and the cache value is set as dirty so that that + # the value will be written to the database on next flush. + # this was needed because some journal entries may exist when running tests, especially l10n demo data. class BaseUsersCommon(BaseCommon):