[FIX] (website_)sale_coupon: avoid race condition on currency

Creating a new database with only website_sale_coupon installed will
make some (website_)sale_coupon tests fail. This is due to a race condition
messing with the value of the pricelist product.list0 currency.

The tests are failing due to amounts being compared after the USD
currency rate of 1.2834 has been applied.

Example on a 10% discount:

expected:
>>> 320 * 0.9
288.0

actual:
>>> 320 * 1.2834 * 0.9
369.62

This is due to
https://github.com/odoo/odoo/blob/3cf9cfc985950c30c6b76480f77f5ffe53650b24/addons/website_sale/data/demo.xml#L228
overriding the value to USD. The tests should not rely on this.

This commit aims to ensure the currency is enforced before each test run.

closes #4371

Signed-off-by: Christophe Simonis <chs@odoo.com>

X-port/Cherry-pick of odoo/enterprise@c1cc464c44
This commit is contained in:
Johan Demaret Rivarola
2019-06-05 18:18:52 +02:00
committed by Christophe Simonis
parent 0f9823e216
commit 218d5ce6a8
2 changed files with 17 additions and 3 deletions
+7 -2
View File
@@ -1,14 +1,19 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from openerp.tests import common
from odoo.addons.sale.tests.test_sale_product_attribute_value_config import TestSaleProductAttributeValueSetup
class TestSaleCouponCommon(common.TransactionCase):
class TestSaleCouponCommon(TestSaleProductAttributeValueSetup):
def setUp(self):
super(TestSaleCouponCommon, self).setUp()
# set currency to not rely on demo data and avoid possible race condition
self.currency_ratio = 1.0
pricelist = self.env.ref('product.list0')
pricelist.currency_id = self._setup_currency(self.currency_ratio)
# Set all the existing programs to active=False to avoid interference
self.env['sale.coupon.program'].search([]).write({'active': False})
@@ -1,14 +1,23 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import HttpCase, tagged
from odoo.addons.sale.tests.test_sale_product_attribute_value_config import TestSaleProductAttributeValueSetup
@tagged('post_install', '-at_install')
class TestUi(HttpCase):
class TestUi(TestSaleProductAttributeValueSetup, HttpCase):
post_install = True
at_install = False
def setUp(self):
super(TestUi, self).setUp()
# set currency to not rely on demo data and avoid possible race condition
self.currency_ratio = 1.0
pricelist = self.env.ref('product.list0')
pricelist.currency_id = self._setup_currency(self.currency_ratio)
def test_01_admin_shop_sale_coupon_tour(self):
# pre enable "Show # found" option to avoid race condition...
self.env.ref("website_sale.search count").write({"active": True})