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_with_code_operations.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/test_program_with_code_operations.py') diff --git a/tests/test_program_with_code_operations.py b/tests/test_program_with_code_operations.py index b39e02b98c7..50457f5c14c 100644 --- a/tests/test_program_with_code_operations.py +++ b/tests/test_program_with_code_operations.py @@ -42,10 +42,12 @@ class TestProgramWithCodeOperations(TestSaleCouponCommon): self.env['sale.coupon.apply.code'].with_context(active_id=order.id).create({ 'coupon_code': self.code_promotion_program.coupon_ids.code }).process_coupon() + order.recompute_coupon_lines() self.assertEqual(len(order.order_line.ids), 2) # Remove the product A from the sale order order.write({'order_line': [(2, order.order_line[0].id, False)]}) + order.recompute_coupon_lines() self.assertEqual(len(order.order_line.ids), 0) def test_on_next_order_reward_promo_program(self): @@ -71,6 +73,7 @@ def test_on_next_order_reward_promo_program(self): 'coupon_code': 'bleurk' }).process_coupon() # Ensure that the coupon is correctly generated + order.recompute_coupon_lines() self.assertEqual(len(self.immediate_promotion_program.coupon_ids.ids), 1) generated_coupon = self.immediate_promotion_program.coupon_ids[0] @@ -89,4 +92,5 @@ def test_on_next_order_reward_promo_program(self): 'coupon_code': generated_coupon.code }) # Ensure that the generated coupon is valid + order.recompute_coupon_lines() self.assertEqual(len(order.order_line.ids), 2) -- cgit v1.2.3