From 89f8a6267233d194d93b0b53b69a1f3790bfa142 Mon Sep 17 00:00:00 2001 From: Volodiay616 <108336612+Volodiay616@users.noreply.github.com> Date: Mon, 14 Aug 2023 22:03:32 -0500 Subject: [PATCH] [FIX] sale_promotion_discount_in_field: apply code when Promo code used, promotion was not added to Applied Promo Program of current order. --- .../wizard/__init__.py | 1 + .../wizard/sale_coupon_apply_code.py | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 sale_promotion_discount_in_field/wizard/__init__.py create mode 100644 sale_promotion_discount_in_field/wizard/sale_coupon_apply_code.py diff --git a/sale_promotion_discount_in_field/wizard/__init__.py b/sale_promotion_discount_in_field/wizard/__init__.py new file mode 100644 index 000000000..cfca3edcd --- /dev/null +++ b/sale_promotion_discount_in_field/wizard/__init__.py @@ -0,0 +1 @@ +from . import sale_coupon_apply_code diff --git a/sale_promotion_discount_in_field/wizard/sale_coupon_apply_code.py b/sale_promotion_discount_in_field/wizard/sale_coupon_apply_code.py new file mode 100644 index 000000000..0cf9f2370 --- /dev/null +++ b/sale_promotion_discount_in_field/wizard/sale_coupon_apply_code.py @@ -0,0 +1,27 @@ +from odoo import models +from odoo.osv import expression + + +class SaleCouponApplyCode(models.TransientModel): + _inherit = "sale.coupon.apply.code" + + def apply_coupon(self, order, coupon_code): + # OVERRIDE to apply the program to the order without reward lines + error_status = {} + program_domain = order._get_coupon_program_domain() + program_domain = expression.AND( + [program_domain, [("promo_code", "=", coupon_code)]] + ) + program = self.env["coupon.program"].search(program_domain) + if ( + program + and program.reward_type == "discount_line" + and program.promo_applicability != "on_next_order" + ): + error_status = program._check_promo_code(order, coupon_code) + if not error_status: + order._create_reward_line(program) + order.code_promo_program_id = program + else: + return super().apply_coupon(order, coupon_code) + return error_status