Skip to content

Commit

Permalink
fix: Separate date validation and allow unlimited max use if 0 (#1368)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperMetal authored Jun 8, 2021
1 parent f9ce281 commit a0f076f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions erpnext/controllers/selling_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a0f076f

Please sign in to comment.