From aeaadb1e300b622abf54d35364a471463b504a2e Mon Sep 17 00:00:00 2001 From: "bhaveshkumar.j" Date: Mon, 21 Oct 2024 18:22:30 +0000 Subject: [PATCH] fix: coupon code validation logic (cherry picked from commit d04257a32dd705868cc662399dcc893003a5b59c) # Conflicts: # erpnext/accounts/doctype/pricing_rule/utils.py --- erpnext/accounts/doctype/pricing_rule/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index a74dfea2cca..4093462d645 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -728,6 +728,7 @@ def get_pricing_rule_items(pr_doc, other_items=False) -> list: def validate_coupon_code(coupon_name): coupon = frappe.get_doc("Coupon Code", coupon_name) +<<<<<<< HEAD if coupon.valid_from: if coupon.valid_from > getdate(today()): @@ -736,9 +737,17 @@ def validate_coupon_code(coupon_name): if coupon.valid_upto < getdate(today()): frappe.throw(_("Sorry, this coupon code's validity has expired")) elif coupon.used >= coupon.maximum_use: +======= + if coupon.valid_from and coupon.valid_from > getdate(today()): + frappe.throw(_("Sorry, this coupon code's validity has not started")) + elif coupon.valid_upto and coupon.valid_upto < getdate(today()): + frappe.throw(_("Sorry, this coupon code's validity has expired")) + elif coupon.maximum_use and coupon.used >= coupon.maximum_use: +>>>>>>> d04257a32d (fix: coupon code validation logic) frappe.throw(_("Sorry, this coupon code is no longer valid")) + def update_coupon_code_count(coupon_name, transaction_type): coupon = frappe.get_doc("Coupon Code", coupon_name) if coupon: