From 75f39e07b29eeadea06109e22c92809d513daeb9 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 12 Mar 2018 15:57:48 +0100 Subject: [PATCH 1/5] [FIX] sale_coupon: can duplicate sale order lines Fix the commit a42c27f99e0061b7c4f6597e4 which inverts the initial filter. The change remove all sale order lines for the simple order create in the backend. opw-1819977 --- models/sale_order.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/models/sale_order.py b/models/sale_order.py index 12876e46c4c..d4b8f895989 100644 --- a/models/sale_order.py +++ b/models/sale_order.py @@ -37,9 +37,8 @@ class SaleOrder(models.Model): order._update_existing_reward_lines() def copy(self, default=None): - order = super(SaleOrder, self).copy(dict(default or {}, order_line=False)) - for line in self._get_reward_lines(): - line.copy({'order_id': order.id}) + order = super(SaleOrder, self).copy(default) + order._get_reward_lines().unlink() order.with_context(sale_coupon_no_loop=False)._create_new_no_code_promo_reward_lines() return order From ce054681f0484891ee71561cc025cf7395a7f143 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 12 Mar 2018 14:49:51 +0100 Subject: [PATCH 2/5] [FIX] sale_coupon: change unit When the reward product is changed, the corresponding UOM should be adapted. opw-1823149 --- models/sale_coupon_program.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/models/sale_coupon_program.py b/models/sale_coupon_program.py index 6c487f7f281..1e702ef1a8c 100644 --- a/models/sale_coupon_program.py +++ b/models/sale_coupon_program.py @@ -73,6 +73,11 @@ class SaleCouponProgram(models.Model): if self.promo_code_usage == 'no_code_needed': self.promo_code = False + @api.onchange('reward_product_id') + def _onchange_reward_product_id(self): + if self.reward_product_id: + self.reward_product_uom_id = self.reward_product_id.uom_id + @api.model def create(self, vals): program = super(SaleCouponProgram, self).create(vals) From 08dc1fc268ed7111c4688a6b397bcf1f82c58ded Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 15 Mar 2018 17:40:54 +0100 Subject: [PATCH 3/5] [FIX] sale_coupon: fix test Following https://github.com/odoo/odoo/commit/87c09b8ebcea950b628e5c7adfe847b9f8b6c031 the default COA taxes are not used as sale/purchase default taxes. --- tests/common.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/common.py b/tests/common.py index 1f4c5d4dd7b..38c959fb87c 100644 --- a/tests/common.py +++ b/tests/common.py @@ -25,17 +25,34 @@ class TestSaleCouponCommon(common.TransactionCase): self.uom_unit = self.env.ref('product.product_uom_unit') + # Taxes + self.tax_15pc_excl = self.env['account.tax'].create({ + 'name': "Tax 15%", + 'amount_type': 'percent', + 'amount': 15, + 'type_tax_use': 'sale', + }) + + self.tax_10pc_incl = self.env['account.tax'].create({ + 'name': "10% Tax incl", + 'amount_type': 'percent', + 'amount': 10, + 'price_include': True, + }) + #products self.product_A = self.env['product.product'].create({ 'name': 'Product A', 'list_price': 100, - 'sale_ok': True + 'sale_ok': True, + 'taxes_id': [(6, 0, [self.tax_15pc_excl.id])], }) self.product_B = self.env['product.product'].create({ 'name': 'Product B', 'list_price': 5, - 'sale_ok': True + 'sale_ok': True, + 'taxes_id': [(6, 0, [self.tax_15pc_excl.id])], }) # Immediate Program By A + B: get B free @@ -57,10 +74,3 @@ class TestSaleCouponCommon(common.TransactionCase): 'rule_products_domain': "[('id', 'in', [%s])]" % (self.product_A.id), 'active': True, }) - - self.tax_10pc_incl = self.env['account.tax'].create({ - 'name': "10% Tax incl", - 'amount_type': 'percent', - 'amount': 10, - 'price_include': True, - }) From 61d049ab4c1d425d0d7df25d96ee0f0e7a0bbd99 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Fri, 9 Mar 2018 17:39:58 +0100 Subject: [PATCH 4/5] [FIX] sale_coupon: recompute coupon before confirmation Instead of after If "Lock Confirmed Orders" option is checked, a sale order with a coupon can not be confirmed as the lines are recomputed after the change of state Backport of https://github.com/odoo/enterprise/commit/073ca5866a3a7006a03b99c4681e60da7a6e6efd Closes #1967 --- models/sale_order.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/models/sale_order.py b/models/sale_order.py index d4b8f895989..d3789d5413b 100644 --- a/models/sale_order.py +++ b/models/sale_order.py @@ -43,10 +43,9 @@ class SaleOrder(models.Model): return order def action_confirm(self): - res = super(SaleOrder, self).action_confirm() self.recompute_coupon_lines() self.generated_coupon_ids.write({'state': 'new'}) - return res + return super(SaleOrder, self).action_confirm() def action_cancel(self): res = super(SaleOrder, self).action_cancel() From b6eb3a871b66d45747a1e9c7bd39cd563db5b660 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Fri, 16 Mar 2018 11:28:03 +0100 Subject: [PATCH 5/5] [FIX] sale_coupon: don't recompute coupon when confirming a quote Before this commit: When you 'CONFIRM SALE', it would recompute the coupons just before confirming the quote. This would cause 2 issues: 1. You had no way to know what the generated SO will looks like (maybe unless you know perfectly all the coupon promotions?). You would end up with a 'surprise' SO that could be totally different from the quote you just confirmed. 2. You had no way to cancel or prevent a coupon to be applied even if you wanted to. Eg: you don't wan't to offer this free forth iPad or this 10% discount to that customer or this week. Obviously, you could set all your coupons to be used with a code so the recompute won't add any coupon to the quote but that would not make sense since you would be limited to one coupon per SO. At the end, there is a `UPDATE PROMOTIONS` on the quote which it's only purpose is to recompute the coupons. The good practice would be to use that button instead of using the confirm quote step to recompute the coupons. Comes from #1967 (see review comment) --- models/sale_order.py | 1 - 1 file changed, 1 deletion(-) diff --git a/models/sale_order.py b/models/sale_order.py index b7c2fd7227e..79d39dbb84e 100644 --- a/models/sale_order.py +++ b/models/sale_order.py @@ -44,7 +44,6 @@ class SaleOrder(models.Model): return order def action_confirm(self): - self.recompute_coupon_lines() self.generated_coupon_ids.write({'state': 'new'}) return super(SaleOrder, self).action_confirm()