Skip to content

Commit

Permalink
[IMP] sale_loyalty_exclude: restrict returned programs if loyalty_exc…
Browse files Browse the repository at this point in the history
…lusions

* Inherit get_claimable_rewards and try_apply_program to restrict the returned rewards
if the product have the check loyalty_exclude active in order to hide the claim button
in the website.
  • Loading branch information
Pablocce committed Oct 10, 2024
1 parent 3b4f9ad commit 02120ba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions sale_invoice_policy/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"views/res_config_settings_view.xml",
"views/sale_view.xml",
],
"installable": False,
"post_init_hook": "post_init_hook",
}
19 changes: 19 additions & 0 deletions sale_loyalty_exclude/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,22 @@ def _get_no_effect_on_threshold_lines(self):
self.ensure_one()
lines = self.order_line.filtered(lambda line: line.product_id.loyalty_exclude)
return lines | super()._get_no_effect_on_threshold_lines()

def _has_non_loyalty_exclude(self):
"""Check if any order line does not have loyalty_exclude set to True."""
for line in self.order_line:
if not line.product_id.loyalty_exclude:
return True
return False

Check warning on line 23 in sale_loyalty_exclude/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_loyalty_exclude/models/sale_order.py#L22-L23

Added lines #L22 - L23 were not covered by tests

def _get_claimable_rewards(self, forced_coupons=None):
if not self._has_non_loyalty_exclude():
return {}

Check warning on line 27 in sale_loyalty_exclude/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_loyalty_exclude/models/sale_order.py#L27

Added line #L27 was not covered by tests
else:
return super()._get_claimable_rewards(forced_coupons=forced_coupons)

Check warning on line 29 in sale_loyalty_exclude/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_loyalty_exclude/models/sale_order.py#L29

Added line #L29 was not covered by tests

def _try_apply_program(self, program, coupon=None):
if not self._has_non_loyalty_exclude():
return {"error": ("This code is invalid.")}

Check warning on line 33 in sale_loyalty_exclude/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_loyalty_exclude/models/sale_order.py#L33

Added line #L33 was not covered by tests
else:
return super()._try_apply_program(program, coupon=coupon)

Check warning on line 35 in sale_loyalty_exclude/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_loyalty_exclude/models/sale_order.py#L35

Added line #L35 was not covered by tests

0 comments on commit 02120ba

Please sign in to comment.