From 6678bef0b05cf01a9ac24fa48934b8b14265c710 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Tue, 29 Oct 2024 19:47:58 +0100 Subject: [PATCH] [FIX] sale_tier_validation: Basic compatibility with sale_loyalty 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 --- sale_tier_validation/models/sale_order.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sale_tier_validation/models/sale_order.py b/sale_tier_validation/models/sale_order.py index 3c7eecf070f..0a0f7bbe5d8 100644 --- a/sale_tier_validation/models/sale_order.py +++ b/sale_tier_validation/models/sale_order.py @@ -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 + ( + 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