[FIX] sale_coupon: delete 'sibling' lines when deleting a reward line

A discount on products with different taxes will result in as many discount
lines as there is different taxes.

Before this commit, removing one of these lines would not do anything else.
Then, recomputing the coupon would regenerate/add back this line.
On e-commerce, it means you would never be able to remove the program by
deleting its reward lines if there are multiple taxes (and so multiple lines)
since it would `recompute_coupon_lines` right away, adding it back directly.

Now, this commit will ensure that removing one of these lines will also remove
the other ones coming from this program on other taxes.
It means removing a regular product will remove it's reward line that will also
now remove the other program's discount line on other taxes and ultimately will
remove the program from the SO since all the program reward lines got removed.
(It won't affect auto applied program since it will be regenerated afterward)

task-1866977
Related to #2224
This commit is contained in:
Romain Derie
2018-09-13 15:16:57 +02:00
parent 194b83eeea
commit 9ec4ad31a9
+1
View File
@@ -50,6 +50,7 @@ class SalesOrderLine(models.Model):
def unlink(self):
# Due to delivery_set and delivery_unset methods that are called everywhere, don't unlink
# reward lines if it's a free shipping
self = self.exists()
orders = self.mapped('order_id')
applied_programs = orders.mapped('no_code_promo_program_ids') + \
orders.mapped('code_promo_program_id') + \