fix(various)
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
index 0979854..a44ac00 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
@@ -237,14 +237,14 @@
 def get_pricing_rules(args):
 	def _get_tree_conditions(parenttype, allow_blank=True):
 		field = frappe.scrub(parenttype)
-		if not frappe.flags.tree_conditions:
-			frappe.flags.tree_conditions = {}
-		key = (parenttype, args[field], )
-		if key in frappe.flags.tree_conditions:
-			return frappe.flags.tree_conditions[key]
-
 		condition = ""
 		if args.get(field):
+			if not frappe.flags.tree_conditions:
+				frappe.flags.tree_conditions = {}
+			key = (parenttype, args[field], )
+			if key in frappe.flags.tree_conditions:
+				return frappe.flags.tree_conditions[key]
+
 			try:
 				lft, rgt = frappe.db.get_value(parenttype, args[field], ["lft", "rgt"])
 			except TypeError:
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index b9efe53..419afe1 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -139,10 +139,11 @@
 
 	def validate_max_discount(self):
 		for d in self.get("items"):
-			discount = flt(frappe.get_cached_value("Item", d.item_code, "max_discount"))
+			if d.item_code:
+				discount = flt(frappe.get_cached_value("Item", d.item_code, "max_discount"))
 
-			if discount and flt(d.discount_percentage) > discount:
-				frappe.throw(_("Maximum discount for Item {0} is {1}%").format(d.item_code, discount))
+				if discount and flt(d.discount_percentage) > discount:
+					frappe.throw(_("Maximum discount for Item {0} is {1}%").format(d.item_code, discount))
 
 	def set_qty_as_per_stock_uom(self):
 		for d in self.get("items"):