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

[FIX] sale_coupon: perf improvement

_get_applicable_no_code_promo_programs always returns a subset of
_get_applicable_programs ...

We can thus avoid summing the results from the two methods, which
triggered unnecessary operations and resulted in a recordset with
useless duplicates...

Furthermore, as _get_applicable_programs returned recordset is only
used to compare to other recordsets (substraction or comparison),
it doesn't need to be sorted by the model order.  We can thus
safely order the result by id instead, to reduce the query complexity.
parent bb2a7e84
Branches
Tags
No related merge requests found
......@@ -260,14 +260,15 @@ class SaleOrder(models.Model):
def _get_applicable_programs(self):
"""
This method is used to return the valid applicable programs on given order.
param: order - The sale order for which method will get applicable programs.
"""
self.ensure_one()
programs = self.env['sale.coupon.program'].search([
('company_id', 'in', [self.company_id.id, False])
])._filter_programs_from_common_rules(self)
if self.promo_code:
programs._filter_promo_programs_with_code(self)
], order="id")._filter_programs_from_common_rules(self)
# no impact code...
# should be programs = programs.filtered if we really want to filter...
# if self.promo_code:
# programs._filter_promo_programs_with_code(self)
return programs
def _get_applicable_no_code_promo_program(self):
......@@ -368,7 +369,7 @@ class SaleOrder(models.Model):
applied_programs = order._get_applied_programs()
applicable_programs = self.env['sale.coupon.program']
if applied_programs:
applicable_programs = order._get_applicable_no_code_promo_program() + order._get_applicable_programs() + order._get_valid_applied_coupon_program()
applicable_programs = order._get_applicable_programs() + order._get_valid_applied_coupon_program()
applicable_programs = applicable_programs._keep_only_most_interesting_auto_applied_global_discount_program()
programs_to_remove = applied_programs - applicable_programs
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment