[FIX] sale_coupon: do not deduce reward quantity on current_order

Before this commit:
1. We were checking if the rewards were in the SO even if it was 'next_order'
   program.
2. We were deducing the rewards quantity for 'next_order' program when checking
   if we had enough products to meet the program requirements.

Now:
1. We don't verify if the reward is on the SO if the program is 'next_order'
2. We don't deduce reward quantity when checking if enough products to meet the
   program requirements if the program is 'next_order'

opw-1907211
Closes #3062
This commit is contained in:
Romain Derie
2018-11-15 15:56:25 +01:00
parent 7b99c0db92
commit e8efcb1bc3
2 changed files with 36 additions and 4 deletions
+28
View File
@@ -489,3 +489,31 @@ class TestSaleCouponProgramNumbers(TestSaleCouponCommon):
fixed_amount_program.write({'active': False}) # Check archived product will remove discount lines on recompute
order.recompute_coupon_lines()
self.assertEqual(len(order.order_line.ids), 1, "Archiving the program should remove the program reward line")
def test_program_next_order(self):
order = self.empty_order
self.env['sale.coupon.program'].create({
'name': 'Free Keyboard if at least 1 article',
'promo_code_usage': 'no_code_needed',
'promo_applicability': 'on_next_order',
'program_type': 'promotion_program',
'reward_type': 'product',
'reward_product_id': self.wirelessKeyboard.id,
'rule_min_quantity': 2,
})
sol1 = self.env['sale.order.line'].create({
'product_id': self.iPadMini.id,
'name': 'iPad Mini',
'product_uom_qty': 1.0,
'order_id': order.id,
})
order.recompute_coupon_lines()
self.assertEqual(len(order.order_line.ids), 1, "Nothing should be added to the cart")
self.assertEqual(len(order.generated_coupon_ids), 0, "No coupon should have been generated yet")
sol1.product_uom_qty = 2
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 (2)")
self.assertEqual(len(generated_coupon), 1, "A coupon should have been generated")
self.assertEqual(generated_coupon.state, 'reserved', "The coupon should be reserved")