From 8f6ec5875750c355a6bc77ca5e866f440bf8c4f6 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Wed, 21 Jun 2017 10:24:02 +0200 Subject: [FIX] sale_coupon: Don't update automatic rewards on the fly Purpose ======= Currently we are updating the coupon rewards on the fly when creating/modifying/deleting a sales order line. To avoid multiple searches on res_partners and product to know whether the customer/product is valid on the sale coupon program, we store the applicable customers and products on the program according to the domain defined on it. This brings 2 issues: - The customers/products stored on the program are not updated (Was the original spec) - The checks are numerous and maybe overkill for the given results Specification ============= - Don't recompute the reward lines on SO modifications. Add a button to compute the line by hand and make an automatic compute on the SO validation or on the page shop/payment. - When recomputing the reward lines, make a search on the res_partners and products instead. Now that the action is not triggered so often we can afford to make a search. - Don't use the fields rule_partners_domain and rule_products_domain. This should be removed in master. - The field is_public_included is useless now. And we decided to make the coupon available for all the partners if they fit the domain on the program. --- tests/test_program_without_code_operations.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests/test_program_without_code_operations.py') diff --git a/tests/test_program_without_code_operations.py b/tests/test_program_without_code_operations.py index 32f2edf6a93..6d789e5b115 100644 --- a/tests/test_program_without_code_operations.py +++ b/tests/test_program_without_code_operations.py @@ -22,6 +22,7 @@ class TestProgramWithoutCodeOperations(TestSaleCouponCommon): 'product_uom_qty': 1.0, }) ]}) + order.recompute_coupon_lines() 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 @@ -33,14 +34,17 @@ class TestProgramWithoutCodeOperations(TestSaleCouponCommon): 'product_uom_qty': 1.0, }) ]}) + order.recompute_coupon_lines() 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})]}) + order.recompute_coupon_lines() 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})]}) + order.recompute_coupon_lines() 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") @@ -50,5 +54,6 @@ class TestProgramWithoutCodeOperations(TestSaleCouponCommon): (1, order.order_line[0].id, {'product_uom_qty': 2.0}), (2, order.order_line[0].id, False) ]}) + order.recompute_coupon_lines() 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") -- cgit v1.2.3