From 218d5ce6a8229dd37253665c1e6071ea66c01591 Mon Sep 17 00:00:00 2001 From: Johan Demaret Rivarola Date: Fri, 17 May 2019 13:13:06 +0000 Subject: [PATCH] [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 X-port/Cherry-pick of odoo/enterprise@c1cc464c44393443ef0ad595809dfd02e5b34577 --- addons/sale_coupon/tests/common.py | 9 +++++++-- .../tests/test_shop_sale_coupon.py | 11 ++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/addons/sale_coupon/tests/common.py b/addons/sale_coupon/tests/common.py index 03820578f64..fec5d669aba 100644 --- a/addons/sale_coupon/tests/common.py +++ b/addons/sale_coupon/tests/common.py @@ -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}) diff --git a/addons/website_sale_coupon/tests/test_shop_sale_coupon.py b/addons/website_sale_coupon/tests/test_shop_sale_coupon.py index 1ab113c83a8..4910d95f827 100644 --- a/addons/website_sale_coupon/tests/test_shop_sale_coupon.py +++ b/addons/website_sale_coupon/tests/test_shop_sale_coupon.py @@ -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})