[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 3752b3166e.
Cf runbot build error 22351
closes odoo/odoo#130201
X-original-commit: a73b5fce4fb02eefc681c55eab8f57cd35105226
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
@@ -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):
|
||||
"""
|
||||
|
||||
@@ -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):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user