diff options
| author | pgu-odoo <pgu@openerp.com> | 2016-12-20 14:33:35 +0100 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2016-12-20 14:46:00 +0100 |
| commit | 5260d22c4d60cf73d22fd179bea142a4c2d00b36 (patch) | |
| tree | 161c2c35f9e8f070aadd5241a5b850702e3fe8d5 /tests/test_program_without_code_operations.py | |
[ADD] sale_coupon: introduce coupon mechanism on sales order
Introduces 2 new concepts:
Promotion programs:
===================
Using promotion programs allows you to propose to your customers:
- Promotional offers limited in time or a limited order number.
- Public code printed in advertisements, magasines, etc.
- Specific offers based on a customers group or a product set.
- A combination of the preceeding points.
You may choose to apply the program reward immediately on the sales order or to propose the reward for a next order. In the second case a coupon will be generated at the order confirmation for the customer to use it later.
Coupon programs:
================
Using coupon programs allows you to propose to your customers:
- Free products or discounts if some conditions on products or purchased amount are met.
- Promotional offers limited in time.
- Generate coupons for a customers group.
- Specific offers based on a customers group or a product set.
- A combination of the preceeding points.
A coupon is applied by entering a valid code if the program rules are met and if the reward is already in the order lines.
Diffstat (limited to 'tests/test_program_without_code_operations.py')
| -rw-r--r-- | tests/test_program_without_code_operations.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/test_program_without_code_operations.py b/tests/test_program_without_code_operations.py new file mode 100644 index 00000000000..32f2edf6a93 --- /dev/null +++ b/tests/test_program_without_code_operations.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from openerp.addons.sale_coupon.tests.common import TestSaleCouponCommon + + +class TestProgramWithoutCodeOperations(TestSaleCouponCommon): + # Test some basic operation (create, write, unlink) on an immediate coupon program on which we should + # apply or remove the reward automatically, as there's no program code. + + def test_immediate_program_basic_operation(self): + + # 2 products A are needed + self.immediate_promotion_program.write({'rule_min_quantity': 2.0}) + order = self.empty_order + # Test case 1 (1 A): Assert that no reward is given, as the product B is missing + order.write({'order_line': [ + (0, False, { + 'product_id': self.product_A.id, + 'name': '1 Product A', + 'product_uom': self.uom_unit.id, + 'product_uom_qty': 1.0, + }) + ]}) + self.assertEqual(len(order.order_line.ids), 1, "The promo offer shouldn't have been applied as the product B isn't in the order") + + # Test case 2 (1 A 1 B): Assert that no reward is given, as the product B is not present in the correct quantity + order.write({'order_line': [ + (0, False, { + 'product_id': self.product_B.id, + 'name': '2 Product B', + 'product_uom': self.uom_unit.id, + 'product_uom_qty': 1.0, + }) + ]}) + self.assertEqual(len(order.order_line.ids), 2, "The promo offer shouldn't have been applied as 2 product A aren't in the order") + + # Test case 3 (2 A 1 B): Assert that the reward is given as the product B is now in the order + order.write({'order_line': [(1, order.order_line[0].id, {'product_uom_qty': 2.0})]}) + self.assertEqual(len(order.order_line.ids), 3, "The promo offert should have been applied, the discount is not created") + + # Test case 4 (1 A 1 B): Assert that the reward is removed as we don't buy 2 products B anymore + order.write({'order_line': [(1, order.order_line[0].id, {'product_uom_qty': 1.0})]}) + self.assertEqual(len(order.order_line.ids), 2, "The promo reward should have been removed as the rules are not matched anymore") + self.assertEqual(order.order_line[0].product_id.id, self.product_A.id, "The wrong line has been removed") + self.assertEqual(order.order_line[1].product_id.id, self.product_B.id, "The wrong line has been removed") + + # Test case 5 (1 B): Assert that the reward is removed when the order is modified and doesn't match the rules anymore + order.write({'order_line': [ + (1, order.order_line[0].id, {'product_uom_qty': 2.0}), + (2, order.order_line[0].id, False) + ]}) + self.assertEqual(len(order.order_line.ids), 1, "The promo reward should have been removed as the rules are not matched anymore") + self.assertEqual(order.order_line.product_id.id, self.product_B.id, "The wrong line has been removed") |
