From f5de88f3b54c78710399530a41cfe165038dbdd1 Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Fri, 28 Jul 2023 16:30:30 +0000 Subject: [PATCH] [FIX] sale: failing test with localizations The test verifying the values of the sale report in a multi-comp & multi-curr environment relies on the fact that the main company is by default in USD. Nevertheless, the test fails when a localization is installed (if it changes the currency of the main company). This commit makes sure the tests always works, and resurrects the right tool for that, which was dropped in commit 3752b3166ec6bbb5c6ea55f96bb521381bf2b2d9. Cf runbot build error 22351 closes odoo/odoo#130201 X-original-commit: a73b5fce4fb02eefc681c55eab8f57cd35105226 Signed-off-by: Victor Feyens (vfe) --- addons/sale/tests/test_sale_report.py | 3 +++ odoo/addons/base/tests/common.py | 10 ++++++++++ 2 files changed, 13 insertions(+) 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):