From a0f076f073fbb48c184888d9ba4445f421b48429 Mon Sep 17 00:00:00 2001 From: Felipe Orellana <1656249+DeveloperMetal@users.noreply.github.com> Date: Tue, 8 Jun 2021 12:45:03 -0400 Subject: [PATCH] fix: Separate date validation and allow unlimited max use if 0 (#1368) --- erpnext/controllers/selling_controller.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 8f9c032ea72e..a403929c8563 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -63,13 +63,13 @@ def validate_coupon(self): if not coupon.enabled: frappe.throw(_("Coupon \"{}\" is not a valid coupon").format(self.coupon_code)) - if coupon.valid_from: - if coupon.valid_from > getdate(today()): - frappe.throw(_("Sorry, this coupon code's validity has not started"), title=_("Coupon Error")) - elif coupon.valid_upto: - if coupon.valid_upto < getdate(today()): - frappe.throw(_("Sorry, this coupon code's validity has expired"), title=_("Coupon Error")) - elif coupon.used >= coupon.maximum_use: + if coupon.valid_from and getdate(today()) < coupon.valid_from: + frappe.throw(_("Sorry, this coupon code's validity has not started"), title=_("Coupon Error")) + + if coupon.valid_upto and getdate(today()) > coupon.valid_upto: + frappe.throw(_("Sorry, this coupon code's validity has expired"), title=_("Coupon Error")) + + if coupon.maximum_use > 0 and coupon.used >= coupon.maximum_use: frappe.throw(_("Sorry, this coupon code is no longer valid"), title=_("Coupon Error")) party_name = self.customer_name if self.doctype != "Quotation" else self.party_name