validate pricing rule discount with item max discount

This commit is contained in:
Nabin Hait 2014-06-20 16:19:55 +05:30 committed by Anand Doshi
parent 9daca108b3
commit 4f6e31eb08

View File

@ -19,6 +19,7 @@ class PricingRule(Document):
self.validate_min_max_qty()
self.cleanup_fields_value()
self.validate_price_or_discount()
self.validate_max_discount()
def validate_mandatory(self):
for field in ["apply_on", "applicable_for"]:
@ -61,6 +62,13 @@ class PricingRule(Document):
if flt(self.get(frappe.scrub(field))) < 0:
throw(_("{0} can not be negative").format(field))
def validate_max_discount(self):
if self.price_or_discount == "Discount Percentage" and self.item_code:
max_discount = frappe.db.get_value("Item", self.item_code, "max_discount")
if flt(self.discount_percentage) > max_discount:
throw(_("Max discount allowed for item: {0} is {1}%".format(self.item_code, max_discount)))
#--------------------------------------------------------------------------------
@frappe.whitelist()