format: better error messages for invalid coupon codes (develop) (#21599)
* format: better error messages for invalid coupon codes * fix: remove unnecessary docstatus check
This commit is contained in:
parent
f984bee5f9
commit
200af04657
@ -4,13 +4,19 @@
|
|||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe, copy, json
|
|
||||||
from frappe import throw, _
|
import copy
|
||||||
|
import json
|
||||||
|
|
||||||
from six import string_types
|
from six import string_types
|
||||||
from frappe.utils import flt, cint, get_datetime, get_link_to_form, today
|
|
||||||
|
import frappe
|
||||||
from erpnext.setup.doctype.item_group.item_group import get_child_item_groups
|
from erpnext.setup.doctype.item_group.item_group import get_child_item_groups
|
||||||
from erpnext.stock.doctype.warehouse.warehouse import get_child_warehouses
|
from erpnext.stock.doctype.warehouse.warehouse import get_child_warehouses
|
||||||
from erpnext.stock.get_item_details import get_conversion_factor
|
from erpnext.stock.get_item_details import get_conversion_factor
|
||||||
|
from frappe import _, throw
|
||||||
|
from frappe.utils import cint, flt, get_datetime, get_link_to_form, getdate, today
|
||||||
|
|
||||||
|
|
||||||
class MultiplePricingRuleConflict(frappe.ValidationError): pass
|
class MultiplePricingRuleConflict(frappe.ValidationError): pass
|
||||||
|
|
||||||
@ -502,18 +508,16 @@ def get_pricing_rule_items(pr_doc):
|
|||||||
return list(set(apply_on_data))
|
return list(set(apply_on_data))
|
||||||
|
|
||||||
def validate_coupon_code(coupon_name):
|
def validate_coupon_code(coupon_name):
|
||||||
from frappe.utils import today,getdate
|
coupon = frappe.get_doc("Coupon Code", coupon_name)
|
||||||
coupon=frappe.get_doc("Coupon Code",coupon_name)
|
|
||||||
if coupon.valid_from:
|
if coupon.valid_from:
|
||||||
if coupon.valid_from > getdate(today()) :
|
if coupon.valid_from > getdate(today()):
|
||||||
frappe.throw(_("Sorry,coupon code validity has not started"))
|
frappe.throw(_("Sorry, this coupon code's validity has not started"))
|
||||||
elif coupon.valid_upto:
|
elif coupon.valid_upto:
|
||||||
if coupon.valid_upto < getdate(today()) :
|
if coupon.valid_upto < getdate(today()):
|
||||||
frappe.throw(_("Sorry,coupon code validity has expired"))
|
frappe.throw(_("Sorry, this coupon code's validity has expired"))
|
||||||
elif coupon.used>=coupon.maximum_use:
|
elif coupon.used >= coupon.maximum_use:
|
||||||
frappe.throw(_("Sorry,coupon code are exhausted"))
|
frappe.throw(_("Sorry, this coupon code is no longer valid"))
|
||||||
else:
|
|
||||||
return
|
|
||||||
|
|
||||||
def update_coupon_code_count(coupon_name,transaction_type):
|
def update_coupon_code_count(coupon_name,transaction_type):
|
||||||
coupon=frappe.get_doc("Coupon Code",coupon_name)
|
coupon=frappe.get_doc("Coupon Code",coupon_name)
|
||||||
|
@ -541,27 +541,31 @@ def show_terms(doc):
|
|||||||
return doc.tc_name
|
return doc.tc_name
|
||||||
|
|
||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def apply_coupon_code(applied_code,applied_referral_sales_partner):
|
def apply_coupon_code(applied_code, applied_referral_sales_partner):
|
||||||
quotation = True
|
quotation = True
|
||||||
if applied_code:
|
|
||||||
coupon_list=frappe.get_all('Coupon Code', filters={"docstatus": ("<", "2"), 'coupon_code':applied_code }, fields=['name'])
|
if not applied_code:
|
||||||
if coupon_list:
|
frappe.throw(_("Please enter a coupon code"))
|
||||||
coupon_name=coupon_list[0].name
|
|
||||||
from erpnext.accounts.doctype.pricing_rule.utils import validate_coupon_code
|
coupon_list = frappe.get_all('Coupon Code', filters={'coupon_code': applied_code})
|
||||||
validate_coupon_code(coupon_name)
|
if not coupon_list:
|
||||||
quotation = _get_cart_quotation()
|
frappe.throw(_("Please enter a valid coupon code"))
|
||||||
quotation.coupon_code=coupon_name
|
|
||||||
|
coupon_name = coupon_list[0].name
|
||||||
|
|
||||||
|
from erpnext.accounts.doctype.pricing_rule.utils import validate_coupon_code
|
||||||
|
validate_coupon_code(coupon_name)
|
||||||
|
quotation = _get_cart_quotation()
|
||||||
|
quotation.coupon_code = coupon_name
|
||||||
|
quotation.flags.ignore_permissions = True
|
||||||
|
quotation.save()
|
||||||
|
|
||||||
|
if applied_referral_sales_partner:
|
||||||
|
sales_partner_list = frappe.get_all('Sales Partner', filters={'referral_code': applied_referral_sales_partner})
|
||||||
|
if sales_partner_list:
|
||||||
|
sales_partner_name = sales_partner_list[0].name
|
||||||
|
quotation.referral_sales_partner = sales_partner_name
|
||||||
quotation.flags.ignore_permissions = True
|
quotation.flags.ignore_permissions = True
|
||||||
quotation.save()
|
quotation.save()
|
||||||
if applied_referral_sales_partner:
|
|
||||||
sales_partner_list=frappe.get_all('Sales Partner', filters={'docstatus': 0, 'referral_code':applied_referral_sales_partner }, fields=['name'])
|
|
||||||
if sales_partner_list:
|
|
||||||
sales_partner_name=sales_partner_list[0].name
|
|
||||||
quotation.referral_sales_partner=sales_partner_name
|
|
||||||
quotation.flags.ignore_permissions = True
|
|
||||||
quotation.save()
|
|
||||||
else:
|
|
||||||
frappe.throw(_("Please enter valid coupon code !!"))
|
|
||||||
else:
|
|
||||||
frappe.throw(_("Please enter coupon code !!"))
|
|
||||||
return quotation
|
return quotation
|
||||||
|
Loading…
x
Reference in New Issue
Block a user