Skip to content
Snippets Groups Projects
Commit 218d5ce6 authored by Johan Demaret Rivarola's avatar Johan Demaret Rivarola Committed by Christophe Simonis
Browse files

[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: default avatarChristophe Simonis <chs@odoo.com>

X-port/Cherry-pick of odoo/enterprise@c1cc464c44393443ef0ad595809dfd02e5b34577
parent 0f9823e2
Branches
Tags
No related merge requests found
# -*- 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})
......
# 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})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment