[FIX] sale_coupon: unvalid next_order programs if needed

Before this commit:
We would never unvalid a `next_order` program (and thus it's generated coupon)

Now:
We also retrieve applied `next_order` programs as we need to check if they are
still valid too

Step to reproduce:
  - Create a program on `next_order` that require $300
  - Add $300 worth of product on a SO
  - Apply program, it will generate a coupon
  - Make the SO total go below $300
  - The generated coupon is still Valid and the client will receive that coupon
    even if it is not supposed to anymore

Closes #3062
This commit is contained in:
Romain Derie
2018-11-15 15:57:06 +01:00
parent e8efcb1bc3
commit 5a75d1aeae
2 changed files with 18 additions and 1 deletions
+13
View File
@@ -517,3 +517,16 @@ class TestSaleCouponProgramNumbers(TestSaleCouponCommon):
self.assertEqual(len(order.order_line.ids), 1, "Nothing should be added to the cart (2)")
self.assertEqual(len(generated_coupon), 1, "A coupon should have been generated")
self.assertEqual(generated_coupon.state, 'reserved', "The coupon should be reserved")
sol1.product_uom_qty = 1
order.recompute_coupon_lines()
generated_coupon = order.generated_coupon_ids
self.assertEqual(len(order.order_line.ids), 1, "Nothing should be added to the cart (3)")
self.assertEqual(len(generated_coupon), 1, "No more coupon should have been generated and the existing one should not have been deleted")
self.assertEqual(generated_coupon.state, 'expired', "The coupon should have been set as expired as it is no more valid since we don't have the required quantity")
sol1.product_uom_qty = 2
order.recompute_coupon_lines()
generated_coupon = order.generated_coupon_ids
self.assertEqual(len(generated_coupon), 1, "We should still have only 1 coupon as we now benefit again from the program but no need to create a new one (see next assert)")
self.assertEqual(generated_coupon.state, 'reserved', "The coupon should be set back to reserved as we had already an expired one, no need to create a new one")