[fix] Use for shopping cart validation in Tax Rule
diff --git a/erpnext/accounts/doctype/tax_rule/tax_rule.js b/erpnext/accounts/doctype/tax_rule/tax_rule.js
index 4c35370..935ea62 100644
--- a/erpnext/accounts/doctype/tax_rule/tax_rule.js
+++ b/erpnext/accounts/doctype/tax_rule/tax_rule.js
@@ -19,19 +19,6 @@
 	frappe.ui.form.trigger("Tax Rule", "tax_type");
 })
 
-frappe.ui.form.on("Tax Rule", "use_for_shopping_cart", function(frm) {
-	if(!frm.doc.use_for_shopping_cart && 
-			(frappe.get_list("Tax Rule", {"use_for_shopping_cart":1}).length == 0)) {
-		frappe.model.get_value("Shopping Cart Settings", "Shopping Cart Settings", 
-				"enabled", function(docfield) {
-			if(docfield.enabled){
-				frm.set_value("use_for_shopping_cart", 1);
-				frappe.throw(__("Shopping Cart is enabled"));
-			}
-		});
-	}
-})
-
 frappe.ui.form.on("Tax Rule", "customer", function(frm) {
 	frappe.call({
 		method:"erpnext.accounts.doctype.tax_rule.tax_rule.get_party_details",
@@ -64,4 +51,4 @@
 			}
 		}
 	});
-});
\ No newline at end of file
+});
diff --git a/erpnext/accounts/doctype/tax_rule/tax_rule.py b/erpnext/accounts/doctype/tax_rule/tax_rule.py
index 7b62082..ce20d3a 100644
--- a/erpnext/accounts/doctype/tax_rule/tax_rule.py
+++ b/erpnext/accounts/doctype/tax_rule/tax_rule.py
@@ -6,7 +6,7 @@
 import frappe
 from frappe import _
 from frappe.model.document import Document
-from frappe.utils import cstr
+from frappe.utils import cstr, cint
 
 class IncorrectCustomerGroup(frappe.ValidationError): pass
 class IncorrectSupplierType(frappe.ValidationError): pass
@@ -20,15 +20,16 @@
 		self.validate_tax_template()
 		self.validate_date()
 		self.validate_filters()
+		self.validate_use_for_shopping_cart()
 
 	def validate_tax_template(self):
 		if self.tax_type== "Sales":
-			self.purchase_tax_template = self.supplier = self.supplier_type= None
+			self.purchase_tax_template = self.supplier = self.supplier_type = None
 			if self.customer:
 				self.customer_group = None
 
 		else:
-			self.sales_tax_template= self.customer = self.customer_group= None
+			self.sales_tax_template = self.customer = self.customer_group = None
 
 			if self.supplier:
 				self.supplier_type = None
@@ -81,6 +82,15 @@
 			if tax_rule[0].priority == self.priority:
 				frappe.throw(_("Tax Rule Conflicts with {0}".format(tax_rule[0].name)), ConflictingTaxRule)
 
+	def validate_use_for_shopping_cart(self):
+		'''If shopping cart is enabled and no tax rule exists for shopping cart, enable this one'''
+		if (not self.use_for_shopping_cart
+			and cint(frappe.db.get_single_value('Shopping Cart Settings', 'enabled'))
+			and not frappe.db.get_value('Tax Rule', {'use_for_shopping_cart': 1, 'name': ['!=', self.name]})):
+
+			self.use_for_shopping_cart = 1
+			frappe.msgprint(_("Enabling 'Use for Shopping Cart', as Shopping Cart is enabled and there should be at least one Tax Rule for Shopping Cart"))
+
 @frappe.whitelist()
 def get_party_details(party, party_type, args=None):
 	out = {}
@@ -109,11 +119,11 @@
 def get_tax_template(posting_date, args):
 	"""Get matching tax rule"""
 	args = frappe._dict(args)
-	conditions = ["""(from_date is null  or from_date = '' or from_date <= '{0}') 
+	conditions = ["""(from_date is null  or from_date = '' or from_date <= '{0}')
 		and (to_date is null  or to_date = '' or to_date >= '{0}')""".format(posting_date)]
 
 	for key, value in args.iteritems():
-		if key in "use_for_shopping_cart":
+		if key=="use_for_shopping_cart":
 			conditions.append("use_for_shopping_cart = {0}".format(1 if value else 0))
 		else:
 			conditions.append("ifnull({0}, '') in ('', '{1}')".format(key, frappe.db.escape(cstr(value))))