Skip to content

Commit

Permalink
[FIX] sale_tier_validation: Basic compatibility with sale_loyalty
Browse files Browse the repository at this point in the history
If you install sale_loyalty, this piece of code:

https://github.com/odoo/odoo/blob/2a7876538e9ea630563e39ee8402b27147d1e428/addons/sale_loyalty/models/sale_order.py#L740

is always executed when confirming a sales order, so it blocks it, no
matter if no coupons are being handled.

This little code avoids this blocking without requiring a glue module,
although further work would be needed if some coupons are applied.

TT51484
  • Loading branch information
pedrobaeza committed Oct 29, 2024
1 parent e6216dd commit 6678bef
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sale_tier_validation/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,18 @@ def _get_accepted_notification_subtype(self):

def _get_rejected_notification_subtype(self):
return "sale_tier_validation.sale_order_tier_validation_rejected"

def _get_fields_to_write_validation(self, vals, records_exception_function):
# Don't block order validation when sale_loyalty is installed and no coupon
# is being handled, due to this code assigning always an empty value:
# https://github.com/odoo/odoo/blob/2a7876538e9ea630563e39ee8402b27147d1e428/
# addons/sale_loyalty/models/sale_order.py#L740
# Done here for not creating a glue module as we can detect the situation. The
# only drawback is that this doesn't have any regression test
(

Check warning on line 31 in sale_tier_validation/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_tier_validation/models/sale_order.py#L31

Added line #L31 was not covered by tests
allowed_field_names,
not_allowed_field_names,
) = super()._get_fields_to_write_validation(vals, records_exception_function)
if "applied_coupon_ids" in vals and not vals.get("applied_coupon_ids"):
allowed_field_names += ["applied_coupon_ids"]
return allowed_field_names, not_allowed_field_names

Check warning on line 37 in sale_tier_validation/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_tier_validation/models/sale_order.py#L36-L37

Added lines #L36 - L37 were not covered by tests

0 comments on commit 6678bef

Please sign in to comment.