Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Added missing date and enabled validations #1363

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion erpnext/accounts/doctype/coupon_code/coupon_code.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"enabled",
"coupon_name",
"coupon_type",
"customer",
Expand Down Expand Up @@ -136,9 +137,16 @@
"fieldtype": "Link",
"label": "Customer Group",
"options": "Customer Group"
},
{
"default": "1",
"fieldname": "enabled",
"fieldtype": "Check",
"in_list_view": 1,
"label": "Enabled"
}
],
"modified": "2020-12-17 00:02:05.148366",
"modified": "2021-06-08 09:44:21.974315",
"modified_by": "[email protected]",
"module": "Accounts",
"name": "Coupon Code",
Expand Down
20 changes: 17 additions & 3 deletions erpnext/controllers/selling_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from __future__ import unicode_literals
import frappe
from frappe.utils import cint, flt, cstr, comma_or
from frappe.utils import cint, flt, cstr, comma_or, getdate, today
from frappe import _, throw
from erpnext.stock.get_item_details import get_bin_details
from erpnext.stock.utils import get_incoming_rate
Expand Down Expand Up @@ -55,8 +55,22 @@ def validate_coupon(self):
if self.meta.get_field("coupon_code"):

if self.coupon_code:
coupon_customer = frappe.get_value("Coupon Code", self.coupon_code, "allowed_customer")
coupon_customer_group = frappe.get_value("Coupon Code", self.coupon_code, "allowed_customer_group")
coupon = frappe.get_doc("Coupon Code", self.coupon_code)

coupon_customer = coupon.allowed_customer
coupon_customer_group = coupon.allowed_customer_group

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:
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
3 changes: 2 additions & 1 deletion erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -720,4 +720,5 @@ erpnext.patches.v13_0.make_mobile_application_access_roles #2021-04-08
erpnext.patches.v13_0.delete_company_custom_fields
execute:frappe.reload_doc('setup', 'doctype', 'company', force=True)
erpnext.patches.v13_0.set_is_used #01-04-2021
erpnext.patches.v13_0.set_coa_batch_in_batch
erpnext.patches.v13_0.set_coa_batch_in_batch
erpnext.patches.v13_0.set_coupon_code_enabled
6 changes: 6 additions & 0 deletions erpnext/patches/v13_0/set_coupon_code_enabled.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import frappe

def execute():
# Default existing coupons to enabled
DeveloperMetal marked this conversation as resolved.
Show resolved Hide resolved
frappe.reload_doc("accounts", "doctype", "coupon_code", force=1)
frappe.db.sql("UPDATE `tabCoupon Code` SET enabled = 1")