diff options
| author | Achraf (abz) <abz@odoo.com> | 2020-10-07 15:15:49 +0000 |
|---|---|---|
| committer | Achraf (abz) <abz@odoo.com> | 2020-10-09 12:13:25 +0000 |
| commit | 4fc64ad1479c7e4cf6d1d7fa639582fd2c9e6d79 (patch) | |
| tree | f0276109f20b9fd29db7583a3acce0c896c69216 /addons | |
| parent | 336d3a428129857e39d98075ca8e95003c09b01e (diff) | |
[FIX] sale_coupon: promotion program with several identical products
Issue
- Create promotion program with product_x
- Create new quotation
- Add product_x on the first line
- Add another product_x on the second line
- Press "Promotions" button
Cause
The attribut reward_product_qty except singleton but order_line contain more than one element
Solution
Take the order line with the higher quantity
opw-2350574
closes odoo/odoo#59634
X-original-commit: 30d66b17ea1829e30de176774c7511aab19851a0
Signed-off-by: agr-odoo <agr-odoo@users.noreply.github.com>
Signed-off-by: Achraf <macadelic80@users.noreply.github.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/sale_coupon/models/sale_order.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/addons/sale_coupon/models/sale_order.py b/addons/sale_coupon/models/sale_order.py index 50d04f68725..3423397bd88 100644 --- a/addons/sale_coupon/models/sale_order.py +++ b/addons/sale_coupon/models/sale_order.py @@ -65,9 +65,9 @@ class SaleOrder(models.Model): def _is_reward_in_order_lines(self, program): self.ensure_one() - return self.order_line.filtered(lambda line: - line.product_id == program.reward_product_id and - line.product_uom_qty >= program.reward_product_quantity) + order_quantity = sum(self.order_line.filtered(lambda line: + line.product_id == program.reward_product_id).mapped('product_uom_qty')) + return order_quantity >= program.reward_product_quantity def _is_global_discount_already_applied(self): applied_programs = self.no_code_promo_program_ids + \ @@ -80,6 +80,7 @@ class SaleOrder(models.Model): order_lines = (self.order_line - self._get_reward_lines()).filtered(lambda x: program._get_valid_products(x.product_id)) max_product_qty = sum(order_lines.mapped('product_uom_qty')) or 1 + total_qty = sum(self.order_line.filtered(lambda x: x.product_id == program.reward_product_id).mapped('product_uom_qty')) # Remove needed quantity from reward quantity if same reward and rule product if program._get_valid_products(program.reward_product_id): # number of times the program should be applied @@ -87,12 +88,12 @@ class SaleOrder(models.Model): # multipled by the reward qty reward_product_qty = program.reward_product_quantity * program_in_order # do not give more free reward than products - reward_product_qty = min(reward_product_qty, self.order_line.filtered(lambda x: x.product_id == program.reward_product_id).product_uom_qty) + reward_product_qty = min(reward_product_qty, total_qty) if program.rule_minimum_amount: order_total = sum(order_lines.mapped('price_total')) - (program.reward_product_quantity * program.reward_product_id.lst_price) reward_product_qty = min(reward_product_qty, order_total // program.rule_minimum_amount) else: - reward_product_qty = min(max_product_qty, self.order_line.filtered(lambda x: x.product_id == program.reward_product_id).product_uom_qty) + reward_product_qty = min(max_product_qty, total_qty) reward_qty = min(int(int(max_product_qty / program.rule_min_quantity) * program.reward_product_quantity), reward_product_qty) # Take the default taxes on the reward product, mapped with the fiscal position |
