From 4c7a32e446669de6caa41dade89a25164c410b4a Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 3 Dec 2015 11:47:38 +0530 Subject: [PATCH] [fix] Toggle required for sales and purchase tax template based on tax type --- erpnext/accounts/doctype/tax_rule/tax_rule.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/tax_rule/tax_rule.js b/erpnext/accounts/doctype/tax_rule/tax_rule.js index 4b059dc564..4c35370eae 100644 --- a/erpnext/accounts/doctype/tax_rule/tax_rule.js +++ b/erpnext/accounts/doctype/tax_rule/tax_rule.js @@ -4,19 +4,26 @@ cur_frm.add_fetch("customer", "customer_group", "customer_group" ); cur_frm.add_fetch("supplier", "supplier_type", "supplier_type" ); -cur_frm.toggle_reqd("sales_tax_template", cur_frm.doc.tax_type=="Sales"); -cur_frm.toggle_reqd("purchase_tax_template", cur_frm.doc.tax_type=="Purchase"); - +frappe.ui.form.on("Tax Rule", "tax_type", function(frm) { + frm.toggle_reqd("sales_tax_template", frm.doc.tax_type=="Sales"); + frm.toggle_reqd("purchase_tax_template", frm.doc.tax_type=="Purchase"); +}) frappe.ui.form.on("Tax Rule", "onload", function(frm) { - if(frm.doc.__islocal){ + if(frm.doc.__islocal) { frm.set_value("use_for_shopping_cart", 1); } }) +frappe.ui.form.on("Tax Rule", "refresh", function(frm) { + 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(!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"));