Skip to content

Commit

Permalink
[FIX] loyalty_criteria_multi_product: Avoiding cross-data in multi-pr…
Browse files Browse the repository at this point in the history
…oduct promotion criteria

When setting up a multi-product promotion, you should not set a minimum
spend amount because if one rule passes, they will all pass.
To avoid misconfiguration, the field is hidden for promotions
with multi-product criteria. In addition, the rule data is cleared
when the criterion is changed so that the promotion is applied
correctly in case of promotion modifications.
  • Loading branch information
pilarvargas-tecnativa committed Nov 19, 2024
1 parent cfc47e1 commit 3c1dbf0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions loyalty_criteria_multi_product/models/loyalty_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ class LoyaltyRule(models.Model):
def _onchange_loyalty_criteria(self):
"""Clear domain so we clear some other fields from the view"""
if self.loyalty_criteria == "multi_product":
self.minimum_amount = 0.00

Check warning on line 27 in loyalty_criteria_multi_product/models/loyalty_rule.py

View check run for this annotation

Codecov / codecov/patch

loyalty_criteria_multi_product/models/loyalty_rule.py#L27

Added line #L27 was not covered by tests
self.product_domain = False
self.product_ids = False
self.product_category_id = False
self.product_tag_id = False
else:
self.loyalty_criteria_ids = False

Check warning on line 33 in loyalty_criteria_multi_product/models/loyalty_rule.py

View check run for this annotation

Codecov / codecov/patch

loyalty_criteria_multi_product/models/loyalty_rule.py#L33

Added line #L33 was not covered by tests
15 changes: 15 additions & 0 deletions loyalty_criteria_multi_product/views/loyalty_rule_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@
name="attrs"
>{'invisible': [('loyalty_criteria', '!=', 'domain')]}</attribute>
</field>
<field name="minimum_amount" position="attributes">
<attribute
name="attrs"
>{'invisible': [('loyalty_criteria', '!=', 'domain')]}</attribute>
</field>
<label for="minimum_amount" position="attributes">
<attribute
name="attrs"
>{'invisible': [('loyalty_criteria', '!=', 'domain')]}</attribute>
</label>
<div class="d-flex flex-row" position="attributes">
<attribute
name="attrs"
>{'invisible': [('loyalty_criteria', '!=', 'domain')]}</attribute>
</div>
<field name="product_domain" position="attributes">
<attribute
name="attrs"
Expand Down

0 comments on commit 3c1dbf0

Please sign in to comment.