[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 cc1bb9224b3d50897e8f16404ed10bcc04225c60.

closes odoo/odoo#60472

X-original-commit: 6d4da47fff9a809f65912d4132a5fd3ccaa37b90
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
Victor Feyens
2020-10-21 15:43:32 +00:00
parent 9a42f49b70
commit 7e26237ffe
2 changed files with 6 additions and 6 deletions
+5 -5
View File
@@ -69,7 +69,7 @@ class CouponProgram(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
@@ -84,7 +84,7 @@ class CouponProgram(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.browse(program_ids)
@@ -118,10 +118,10 @@ class CouponProgram(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:
@@ -133,7 +133,7 @@ class CouponProgram(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 CouponProgram(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(CouponProgram, self)._check_promo_code(order, coupon_code)