Romain Derie b236ca3f15 [FIX] sale_coupon: incorrect free product qty
Note: The following bugs were also impacting the e-commerce.
This commit fixes some bugs related to promotion program offering free product:
  - Create a promotion program that offers an ipad if you buy 3 of them, so the
    fourth is free (reduced in total)

1. Buying 4, getting a free one, removing one, free one remains
  - Create a quotation with 3 ipad, save and update promotions, you don't have
     a free one, which is 'correct'
  - Edit, change the qty to 4 ipad, save, update promotions, you have a free
    ipad (reduced from total), still correct
  - Edit, change the qty back to 3 ipad, update ptomotions, you still have a
    free ipad even if you only bought 3 of them (the way it is designed, the
    free ipad should only appears when you order your fourth).

2. Exponential bug: buy a lot of ipad, get a lot of free ipad then set the qty
to a lower amount, you will have a lot more free ipad than you should.
It can even lead to a negative amount (more free ipad than you paid ipad, but
in that case you won't be able to confirm the sale).
  - Create a quotation with 100 ipad, you get 31 free ipad (which is incorrect,
    see bug 3)
  - Edit and change the qty back to 10 ipad and save
  - Update promotions, you will have 10 ipad to pay and 10 free ipad resulting
    in a null total.

3. Buy X ipad, get Y+Z free instead of Y (lets illustrate with 10)
  - Create a quotation with 10 ipad, you get 3 free ipad instead of 2
  - Indeed, your first 4 ipad should give you a free one
  - Your next 4 ipad should give you a second one (you got 8)
  - The last 2 (to reach 10) are not enough to give you a third free ipad

This is because free products are reward lines in the SO (is_reward_line) but
not linked to an applied_coupon_ids

Now, these reward lines will be considered as such and the coupon computing
will return correct results

This closes #1643
2017-11-29 16:23:56 +01:00
S
Description
No description provided
LGPL-3.0
3.4 GiB
Languages
Python 49.6%
JavaScript 47.8%
SCSS 2%
CSS 0.3%
HTML 0.2%