Skip to content
Snippets Groups Projects
Commit 6d4da47f authored by Victor Feyens's avatar Victor Feyens
Browse files

[FIX] sale_coupon: underterministic recordset order


Recenlty, this method was changed to use set instead of recordsets
to improve the performance of the code.

But set have a non deterministic order, which means the order of the
returned programs returned is not the same, modifying the resulting behavior
as some programs cannot be applied together.

To fix this problem, this commit replaces the set by lists
to ensure the returned recordset keeps the same ordering.

Also rename a potentially conflicting variable caused by the same commit.

Finetuning of commit cc1bb922.

closes odoo/odoo#60417

Signed-off-by: default avatarVictor Feyens (vfe) <vfe@odoo.com>
parent bc2dc85c
Branches
Tags
No related merge requests found
......@@ -203,7 +203,7 @@ class SaleCouponProgram(models.Model):
'amount_untaxed' : order.amount_untaxed - sum(line.price_subtotal for line in no_effect_lines),
'amount_tax' : order.amount_tax - sum(line.price_tax for line in no_effect_lines)
}
program_ids = set()
program_ids = list()
for program in self:
if program.reward_type != 'discount':
# avoid the filtered
......@@ -218,7 +218,7 @@ class SaleCouponProgram(models.Model):
tax_amount = order_amount['amount_tax'] - sum(line.price_tax for line in lines)
program_amount = program._compute_program_amount('rule_minimum_amount', order.currency_id)
if program.rule_minimum_amount_tax_inclusion == 'tax_included' and program_amount <= (untaxed_amount + tax_amount) or program.rule_minimum_amount_tax_inclusion == 'tax_excluded' and program_amount <= untaxed_amount:
program_ids.add(program.id)
program_ids.append(program.id)
return self.env['sale.coupon.program'].browse(program_ids)
......@@ -252,10 +252,10 @@ class SaleCouponProgram(models.Model):
products_qties = dict.fromkeys(products, 0)
for line in order_lines:
products_qties[line.product_id] += line.product_uom_qty
valid_program_ids = set()
valid_program_ids = list()
for program in self:
if not program.rule_products_domain:
valid_program_ids.add(program.id)
valid_program_ids.append(program.id)
continue
valid_products = program._get_valid_products(products)
if not valid_products:
......@@ -267,7 +267,7 @@ class SaleCouponProgram(models.Model):
program.reward_type == 'product' and program._get_valid_products(program.reward_product_id):
ordered_rule_products_qty -= program.reward_product_quantity
if ordered_rule_products_qty >= program.rule_min_quantity:
valid_program_ids.add(program.id)
valid_program_ids.append(program.id)
return self.browse(valid_program_ids)
def _filter_not_ordered_reward_programs(self, order):
......
......@@ -19,6 +19,6 @@ class SaleCouponProgram(models.Model):
return programs
def _check_promo_code(self, order, coupon_code):
if self.reward_type == 'free_shipping' and not any(order.is_delivery for order in order.order_line):
if self.reward_type == 'free_shipping' and not any(line.is_delivery for line in order.order_line):
return {'error': _('The shipping costs are not in the order lines.')}
return super(SaleCouponProgram, self)._check_promo_code(order, coupon_code)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment