diff options
| author | Goffin Simon <sig@odoo.com> | 2019-06-24 17:44:03 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-06-27 19:14:28 +0200 |
| commit | 0247d2f35fdeebdb48e8eafc2ae69d1675158303 (patch) | |
| tree | 3e0fadcbfe5f5678f8bd8c8acbf2ad6e8e6467da /addons/sale_coupon/tests/test_program_with_code_operations.py | |
| parent | 6c5783bd5a8b20dce99b26a81e734a50c168bae0 (diff) | |
[FIX] sale_coupon, sale_coupon_delivery: Wrong discount on promotion program
Let's consider a product P with a unit price = 100€
When a price list PL with a discount of 20% was applied, and
a coupon program CP with a discount of 10% was also applied,
system still calculated the rate based on unit price of the product
and not on the discounted price.
So in this example, the amount of the CP discount was 10€ instead of
8€ because the CP discount was computed on the unit price 100€
instead of the discounted price 80€ (with 20% discount of PL)
opw:2006829
X-port/Cherry-pick of odoo/enterprise@23739e8a71b3a107246fdae9f7208dfcd852ca09
Diffstat (limited to 'addons/sale_coupon/tests/test_program_with_code_operations.py')
| -rw-r--r-- | addons/sale_coupon/tests/test_program_with_code_operations.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/addons/sale_coupon/tests/test_program_with_code_operations.py b/addons/sale_coupon/tests/test_program_with_code_operations.py index 276b20c2221..2a19854f25e 100644 --- a/addons/sale_coupon/tests/test_program_with_code_operations.py +++ b/addons/sale_coupon/tests/test_program_with_code_operations.py @@ -66,6 +66,45 @@ class TestProgramWithCodeOperations(TestSaleCouponCommon): self.assertEqual(len(order.order_line.ids), 0) self.assertEqual(coupon.state, 'new') + def test_coupon_code_with_pricelist(self): + # Test case: Generate a coupon (10% discount) and apply it on an order with a specific pricelist (10% discount) + + self.env['sale.coupon.generate'].with_context(active_id=self.code_promotion_program_with_discount.id).create({ + 'generation_type': 'nbr_coupon', + 'nbr_coupons': 1, + }).generate_coupon() + coupon = self.code_promotion_program_with_discount.coupon_ids + + first_pricelist = self.env['product.pricelist'].create({ + 'name': 'First pricelist', + 'discount_policy': 'with_discount', + 'item_ids': [(0, 0, { + 'compute_price': 'percentage', + 'base': 'list_price', + 'percent_price': 10, + 'applied_on': '3_global', + 'name': 'First discount' + })] + }) + + order = self.empty_order + order.pricelist_id = first_pricelist + order.write({'order_line': [ + (0, False, { + 'product_id': self.product_C.id, + 'name': '1 Product C', + 'product_uom': self.uom_unit.id, + 'product_uom_qty': 1.0, + }) + ]}) + self.env['sale.coupon.apply.code'].with_context(active_id=order.id).create({ + 'coupon_code': coupon.code + }).process_coupon() + order.recompute_coupon_lines() + self.assertEqual(len(order.order_line.ids), 2) + self.assertEqual(coupon.state, 'used') + self.assertEqual(order.amount_total, 81, "SO total should be 81: (10% of 100 with pricelist) + 10% of 90 with coupon code") + def test_on_next_order_reward_promotion_program(self): # The flow: # 1. Create a program `A` that gives a free `Product B` on next order if you buy a an `product A` |
