Skip to content

Commit

Permalink
fix: coupon code limits and add external plaftorm code
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Sep 5, 2024
1 parent 2ae1704 commit 1d82b36
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
17 changes: 13 additions & 4 deletions erpnext/accounts/doctype/coupon_code/coupon_code.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"customer",
"column_break_4",
"coupon_code",
"from_external_ecomm_platform",
"pricing_rule",
"uses",
"valid_from",
Expand Down Expand Up @@ -61,11 +62,12 @@
"unique": 1
},
{
"depends_on": "eval !doc.from_external_ecomm_platform",
"fieldname": "pricing_rule",
"fieldtype": "Link",
"label": "Pricing Rule",
"options": "Pricing Rule",
"reqd": 1
"mandatory_depends_on": "eval: !doc.from_external_ecomm_platform",
"options": "Pricing Rule"
},
{
"fieldname": "uses",
Expand Down Expand Up @@ -114,13 +116,20 @@
"options": "Coupon Code",
"print_hide": 1,
"read_only": 1
},
{
"default": "0",
"fieldname": "from_external_ecomm_platform",
"fieldtype": "Check",
"label": "From External Ecomm Platform"
}
],
"links": [],
"modified": "2024-03-27 13:06:47.220931",
"modified": "2024-06-28 06:17:01.833399",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Coupon Code",
"naming_rule": "By fieldname",
"owner": "Administrator",
"permissions": [
{
Expand Down Expand Up @@ -177,4 +186,4 @@
"states": [],
"title_field": "coupon_name",
"track_changes": 1
}
}
3 changes: 2 additions & 1 deletion erpnext/accounts/doctype/coupon_code/coupon_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ class CouponCode(Document):
coupon_type: DF.Literal["Promotional", "Gift Card"]
customer: DF.Link | None
description: DF.TextEditor | None
from_external_ecomm_platform: DF.Check
maximum_use: DF.Int
pricing_rule: DF.Link
pricing_rule: DF.Link | None
used: DF.Int
valid_from: DF.Date | None
valid_upto: DF.Date | None
Expand Down
7 changes: 5 additions & 2 deletions erpnext/accounts/doctype/pricing_rule/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,15 +731,18 @@ def validate_coupon_code(coupon_name):
elif coupon.valid_upto:
if coupon.valid_upto < getdate(today()):
frappe.throw(_("Sorry, this coupon code's validity has expired"))
elif coupon.used >= coupon.maximum_use:
elif coupon.maximum_use and coupon.used >= coupon.maximum_use:
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:
if transaction_type == "used":
if coupon.used < coupon.maximum_use:
if not coupon.maximum_use:
coupon.used = coupon.used + 1
coupon.save(ignore_permissions=True)
elif coupon.used < coupon.maximum_use:
coupon.used = coupon.used + 1
coupon.save(ignore_permissions=True)
else:
Expand Down

0 comments on commit 1d82b36

Please sign in to comment.