Pricing Rule improvements #565
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.json b/erpnext/accounts/doctype/pricing_rule/pricing_rule.json
index 32df323..2933ffa 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.json
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.json
@@ -1,92 +1,14 @@
{
"autoname": "PRULE.#####",
- "creation": "2014-02-21 15:02:51.000000",
+ "creation": "2014-02-21 15:02:51",
"docstatus": 0,
"doctype": "DocType",
"document_type": "Master",
"fields": [
{
- "fieldname": "basic_section",
- "fieldtype": "Section Break",
- "label": "Basic Section",
- "permlevel": 0
- },
- {
- "default": "Today",
- "fieldname": "valid_from",
- "fieldtype": "Date",
- "label": "Valid From",
- "permlevel": 0
- },
- {
- "fieldname": "valid_upto",
- "fieldtype": "Date",
- "label": "Valid Upto",
- "permlevel": 0
- },
- {
- "fieldname": "col_break1",
- "fieldtype": "Column Break",
- "permlevel": 0
- },
- {
- "fieldname": "priority",
- "fieldtype": "Select",
- "label": "Priority",
- "options": "\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20",
- "permlevel": 0
- },
- {
- "fieldname": "disable",
- "fieldtype": "Check",
- "label": "Disable",
- "permlevel": 0
- },
- {
- "fieldname": "price_discount_section",
- "fieldtype": "Section Break",
- "label": "Price / Discount",
- "permlevel": 0
- },
- {
- "default": "Discount Percentage",
- "fieldname": "price_or_discount",
- "fieldtype": "Select",
- "label": "Price or Discount",
- "options": "\nPrice\nDiscount Percentage",
- "permlevel": 0,
- "reqd": 1
- },
- {
- "fieldname": "col_break2",
- "fieldtype": "Column Break",
- "permlevel": 0
- },
- {
- "depends_on": "eval:doc.price_or_discount==\"Price\"",
- "fieldname": "price",
- "fieldtype": "Float",
- "label": "Price",
- "permlevel": 0
- },
- {
- "depends_on": "eval:doc.price_or_discount==\"Discount Percentage\"",
- "fieldname": "discount_percentage",
- "fieldtype": "Float",
- "label": "Discount Percentage",
- "permlevel": 0
- },
- {
- "depends_on": "eval:doc.price_or_discount==\"Discount Percentage\"",
- "fieldname": "for_price_list",
- "fieldtype": "Link",
- "label": "For Price List",
- "options": "Price List",
- "permlevel": 0
- },
- {
"fieldname": "applicability_section",
"fieldtype": "Section Break",
+ "in_list_view": 0,
"label": "Applicability",
"permlevel": 0
},
@@ -94,6 +16,7 @@
"default": "Item Code",
"fieldname": "apply_on",
"fieldtype": "Select",
+ "in_list_view": 1,
"label": "Apply On",
"options": "\nItem Code\nItem Group\nBrand",
"permlevel": 0,
@@ -103,6 +26,7 @@
"depends_on": "eval:doc.apply_on==\"Item Code\"",
"fieldname": "item_code",
"fieldtype": "Link",
+ "in_list_view": 1,
"label": "Item Code",
"options": "Item",
"permlevel": 0,
@@ -112,6 +36,7 @@
"depends_on": "eval:doc.apply_on==\"Item Group\"",
"fieldname": "item_group",
"fieldtype": "Link",
+ "in_list_view": 1,
"label": "Item Group",
"options": "Item Group",
"permlevel": 0
@@ -120,16 +45,12 @@
"depends_on": "eval:doc.apply_on==\"Brand\"",
"fieldname": "brand",
"fieldtype": "Link",
+ "in_list_view": 1,
"label": "Brand",
"options": "Brand",
"permlevel": 0
},
{
- "fieldname": "col_break3",
- "fieldtype": "Column Break",
- "permlevel": 0
- },
- {
"fieldname": "applicable_for",
"fieldtype": "Select",
"label": "Applicable For",
@@ -203,12 +124,85 @@
"fieldtype": "Float",
"label": "Max Qty",
"permlevel": 0
+ },
+ {
+ "fieldname": "col_break1",
+ "fieldtype": "Column Break",
+ "permlevel": 0
+ },
+ {
+ "default": "Today",
+ "fieldname": "valid_from",
+ "fieldtype": "Date",
+ "label": "Valid From",
+ "permlevel": 0
+ },
+ {
+ "fieldname": "valid_upto",
+ "fieldtype": "Date",
+ "label": "Valid Upto",
+ "permlevel": 0
+ },
+ {
+ "fieldname": "priority",
+ "fieldtype": "Select",
+ "label": "Priority",
+ "options": "\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20",
+ "permlevel": 0
+ },
+ {
+ "fieldname": "disable",
+ "fieldtype": "Check",
+ "label": "Disable",
+ "permlevel": 0
+ },
+ {
+ "fieldname": "price_discount_section",
+ "fieldtype": "Section Break",
+ "label": "Price / Discount",
+ "permlevel": 0
+ },
+ {
+ "default": "Discount Percentage",
+ "fieldname": "price_or_discount",
+ "fieldtype": "Select",
+ "label": "Price or Discount",
+ "options": "\nPrice\nDiscount Percentage",
+ "permlevel": 0,
+ "reqd": 1
+ },
+ {
+ "fieldname": "col_break2",
+ "fieldtype": "Column Break",
+ "permlevel": 0
+ },
+ {
+ "depends_on": "eval:doc.price_or_discount==\"Price\"",
+ "fieldname": "price",
+ "fieldtype": "Float",
+ "label": "Price",
+ "permlevel": 0
+ },
+ {
+ "depends_on": "eval:doc.price_or_discount==\"Discount Percentage\"",
+ "fieldname": "discount_percentage",
+ "fieldtype": "Float",
+ "label": "Discount Percentage",
+ "permlevel": 0
+ },
+ {
+ "depends_on": "eval:doc.price_or_discount==\"Discount Percentage\"",
+ "fieldname": "for_price_list",
+ "fieldtype": "Link",
+ "label": "For Price List",
+ "options": "Price List",
+ "permlevel": 0
}
],
"icon": "icon-gift",
"idx": 1,
"istable": 0,
- "modified": "2014-03-05 18:23:34.000000",
+ "modified": "2014-05-05 11:09:38.244111",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Pricing Rule",
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
index a966142..39260a2 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
@@ -6,19 +6,27 @@
from __future__ import unicode_literals
import frappe
from frappe import throw, _
+from frappe.utils import flt
from frappe.model.document import Document
class PricingRule(Document):
def validate(self):
self.validate_mandatory()
+ self.validate_min_max_qty()
self.cleanup_fields_value()
+
def validate_mandatory(self):
for field in ["apply_on", "applicable_for", "price_or_discount"]:
tocheck = frappe.scrub(self.get(field) or "")
if tocheck and not self.get(tocheck):
throw(_("{0} is required").format(self.meta.get_label(tocheck)), frappe.MandatoryError)
+ def validate_min_max_qty(self):
+ if self.min_qty and self.max_qty and flt(self.min_qty) > flt(self.max_qty):
+ throw(_("Min Qty can not be greater than Max Qty"))
+
+
def cleanup_fields_value(self):
for logic_field in ["apply_on", "applicable_for", "price_or_discount"]:
fieldname = frappe.scrub(self.get(logic_field) or "")