Conditionally toggle Naming Series. Fixes #1526
diff --git a/erpnext/accounts/doctype/journal_voucher/journal_voucher.js b/erpnext/accounts/doctype/journal_voucher/journal_voucher.js
index 1a39ada..e3bf28b 100644
--- a/erpnext/accounts/doctype/journal_voucher/journal_voucher.js
+++ b/erpnext/accounts/doctype/journal_voucher/journal_voucher.js
@@ -111,7 +111,7 @@
 
 cur_frm.cscript.refresh = function(doc) {
 	cur_frm.cscript.is_opening(doc)
-	erpnext.hide_naming_series();
+	erpnext.toggle_naming_series();
 	cur_frm.cscript.voucher_type(doc);
 	if(doc.docstatus==1) {
 		cur_frm.appframe.add_button(__('View Ledger'), function() {
diff --git a/erpnext/buying/doctype/supplier/supplier.js b/erpnext/buying/doctype/supplier/supplier.js
index d6bff6d..99d0e4e 100644
--- a/erpnext/buying/doctype/supplier/supplier.js
+++ b/erpnext/buying/doctype/supplier/supplier.js
@@ -5,32 +5,37 @@
 
 cur_frm.cscript.refresh = function(doc, dt, dn) {
 	cur_frm.cscript.make_dashboard(doc);
-	erpnext.hide_naming_series();
-    
+
+	if(frappe.defaults.get_default("supp_master_name")!="Naming Series") {
+		cur_frm.toggle_display("naming_series", false);
+	} else {
+		erpnext.toggle_naming_series();
+	}
+
 	if(doc.__islocal){
-    	hide_field(['address_html','contact_html']); 
+    	hide_field(['address_html','contact_html']);
 	}
 	else{
 	  	unhide_field(['address_html','contact_html']);
 		// make lists
 		cur_frm.cscript.make_address(doc,dt,dn);
 		cur_frm.cscript.make_contact(doc,dt,dn);
-		
+
 		cur_frm.communication_view = new frappe.views.CommunicationList({
 			list: frappe.get_list("Communication", {"supplier": doc.name}),
 			parent: cur_frm.fields_dict.communication_html.wrapper,
 			doc: doc
-		})		
+		})
   }
 }
 
 cur_frm.cscript.make_dashboard = function(doc) {
 	cur_frm.dashboard.reset();
-	if(doc.__islocal) 
+	if(doc.__islocal)
 		return;
 	if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager"))
 		cur_frm.dashboard.set_headline('<span class="text-muted">Loading...</span>')
-	
+
 	cur_frm.dashboard.add_doctype_badge("Supplier Quotation", "supplier");
 	cur_frm.dashboard.add_doctype_badge("Purchase Order", "supplier");
 	cur_frm.dashboard.add_doctype_badge("Purchase Receipt", "supplier");
@@ -45,10 +50,10 @@
 		callback: function(r) {
 			if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager")) {
 				cur_frm.dashboard.set_headline(
-					__("Total Billing This Year: ") + "<b>" 
+					__("Total Billing This Year: ") + "<b>"
 					+ format_currency(r.message.total_billing, erpnext.get_currency(cur_frm.doc.company))
-					+ '</b> / <span class="text-muted">' + __("Unpaid") + ": <b>" 
-					+ format_currency(r.message.total_unpaid, erpnext.get_currency(cur_frm.doc.company)) 
+					+ '</b> / <span class="text-muted">' + __("Unpaid") + ": <b>"
+					+ format_currency(r.message.total_unpaid, erpnext.get_currency(cur_frm.doc.company))
 					+ '</b></span>');
 			}
 			cur_frm.dashboard.set_badge_count(r.message);
@@ -97,4 +102,4 @@
 	return{
 		filters:{'buying': 1}
 	}
-}
\ No newline at end of file
+}
diff --git a/erpnext/hr/doctype/employee/employee.js b/erpnext/hr/doctype/employee/employee.js
index 49914d2..5d365d0 100644
--- a/erpnext/hr/doctype/employee/employee.js
+++ b/erpnext/hr/doctype/employee/employee.js
@@ -19,7 +19,7 @@
 
 	refresh: function() {
 		var me = this;
-		erpnext.hide_naming_series();
+		erpnext.toggle_naming_series();
 		if(!this.frm.doc.__islocal) {
 			cur_frm.add_custom_button(__('Make Salary Structure'), function() {
 				me.make_salary_structure(this); });
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.js b/erpnext/manufacturing/doctype/production_order/production_order.js
index ba7b275..07e6e11 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.js
+++ b/erpnext/manufacturing/doctype/production_order/production_order.js
@@ -12,7 +12,7 @@
 
 	refresh: function(doc, dt, dn) {
 		this.frm.dashboard.reset();
-		erpnext.hide_naming_series();
+		erpnext.toggle_naming_series();
 		this.frm.set_intro("");
 		cfn_set_fields(doc, dt, dn);
 
diff --git a/erpnext/public/js/transaction.js b/erpnext/public/js/transaction.js
index f101aed..65d91c2 100644
--- a/erpnext/public/js/transaction.js
+++ b/erpnext/public/js/transaction.js
@@ -45,7 +45,7 @@
 
 	refresh: function() {
 		this.frm.clear_custom_buttons();
-		erpnext.hide_naming_series();
+		erpnext.toggle_naming_series();
 		erpnext.hide_company();
 		this.show_item_wise_taxes();
 		this.set_dynamic_labels();
diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js
index a490f70..ef7d03e 100644
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -12,7 +12,7 @@
 			return frappe.boot.sysdefaults.currency;
 	},
 
-	hide_naming_series: function() {
+	toggle_naming_series: function() {
 		if(cur_frm.fields_dict.naming_series) {
 			cur_frm.toggle_display("naming_series", cur_frm.doc.__islocal?true:false);
 		}
diff --git a/erpnext/selling/doctype/campaign/campaign.js b/erpnext/selling/doctype/campaign/campaign.js
index 839ee49..744b20b 100644
--- a/erpnext/selling/doctype/campaign/campaign.js
+++ b/erpnext/selling/doctype/campaign/campaign.js
@@ -2,7 +2,7 @@
 // License: GNU General Public License v3. See license.txt
 
 frappe.ui.form.on("Campaign", "refresh", function(frm) {
-	erpnext.hide_naming_series();
+	erpnext.toggle_naming_series();
 	if(frm.doc.__islocal) {
 		frm.toggle_display("naming_series", frappe.boot.sysdefaults.campaign_naming_by=="Naming Series");
 	}
diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js
index 0bbbd3a..94b8f66 100644
--- a/erpnext/selling/doctype/customer/customer.js
+++ b/erpnext/selling/doctype/customer/customer.js
@@ -20,11 +20,16 @@
 
 cur_frm.cscript.refresh = function(doc, dt, dn) {
 	cur_frm.cscript.setup_dashboard(doc);
-	erpnext.hide_naming_series();
 
-	if(doc.__islocal){		
+	if(frappe.defaults.get_default("cust_master_name")!="Naming Series") {
+		cur_frm.toggle_display("naming_series", false);
+	} else {
+		erpnext.toggle_naming_series();
+	}
+
+	if(doc.__islocal){
 		hide_field(['address_html','contact_html']);
-	}else{		
+	}else{
 		unhide_field(['address_html','contact_html']);
 		// make lists
 		cur_frm.cscript.make_address(doc, dt, dn);
@@ -39,17 +44,17 @@
 
 cur_frm.cscript.setup_dashboard = function(doc) {
 	cur_frm.dashboard.reset(doc);
-	if(doc.__islocal) 
+	if(doc.__islocal)
 		return;
 	if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager"))
 		cur_frm.dashboard.set_headline('<span class="text-muted">'+ __('Loading...')+ '</span>')
-	
+
 	cur_frm.dashboard.add_doctype_badge("Opportunity", "customer");
 	cur_frm.dashboard.add_doctype_badge("Quotation", "customer");
 	cur_frm.dashboard.add_doctype_badge("Sales Order", "customer");
 	cur_frm.dashboard.add_doctype_badge("Delivery Note", "customer");
 	cur_frm.dashboard.add_doctype_badge("Sales Invoice", "customer");
-	
+
 	return frappe.call({
 		type: "GET",
 		method: "erpnext.selling.doctype.customer.customer.get_dashboard_info",
@@ -59,10 +64,10 @@
 		callback: function(r) {
 			if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager")) {
 				cur_frm.dashboard.set_headline(
-					__("Total Billing This Year: ") + "<b>" 
+					__("Total Billing This Year: ") + "<b>"
 					+ format_currency(r.message.total_billing, erpnext.get_currency(cur_frm.doc.company))
-					+ '</b> / <span class="text-muted">' + __("Unpaid") + ": <b>" 
-					+ format_currency(r.message.total_unpaid, erpnext.get_currency(cur_frm.doc.company)) 
+					+ '</b> / <span class="text-muted">' + __("Unpaid") + ": <b>"
+					+ format_currency(r.message.total_unpaid, erpnext.get_currency(cur_frm.doc.company))
 					+ '</b></span>');
 			}
 			cur_frm.dashboard.set_badge_count(r.message);
@@ -122,4 +127,4 @@
 	return{
 		filters:{'selling': 1}
 	}
-}
\ No newline at end of file
+}
diff --git a/erpnext/selling/doctype/lead/lead.js b/erpnext/selling/doctype/lead/lead.js
index c04330d..83639d4 100644
--- a/erpnext/selling/doctype/lead/lead.js
+++ b/erpnext/selling/doctype/lead/lead.js
@@ -30,7 +30,7 @@
 	
 	refresh: function() {
 		var doc = this.frm.doc;
-		erpnext.hide_naming_series();
+		erpnext.toggle_naming_series();
 		this.frm.clear_custom_buttons();
 
 		this.frm.__is_customer = this.frm.__is_customer || this.frm.doc.__is_customer;
diff --git a/erpnext/selling/doctype/opportunity/opportunity.js b/erpnext/selling/doctype/opportunity/opportunity.js
index 3ae33bb..16dc6f2 100644
--- a/erpnext/selling/doctype/opportunity/opportunity.js
+++ b/erpnext/selling/doctype/opportunity/opportunity.js
@@ -81,7 +81,7 @@
 $.extend(cur_frm.cscript, new erpnext.selling.Opportunity({frm: cur_frm}));
 
 cur_frm.cscript.refresh = function(doc, cdt, cdn) {
-	erpnext.hide_naming_series();
+	erpnext.toggle_naming_series();
 	cur_frm.clear_custom_buttons();
 	
 	if(doc.docstatus === 1 && doc.status!=="Lost") {
diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js
index 6037c23..c4f0341 100644
--- a/erpnext/stock/doctype/item/item.js
+++ b/erpnext/stock/doctype/item/item.js
@@ -7,8 +7,14 @@
 	// make sensitive fields(has_serial_no, is_stock_item, valuation_method)
 	// read only if any stock ledger entry exists
 
-	cur_frm.cscript.make_dashboard()
-	erpnext.hide_naming_series();
+	cur_frm.cscript.make_dashboard();
+
+	if (frappe.defaults.get_default("item_naming_by")!="Naming Series") {
+		cur_frm.toggle_display("naming_series", false);
+	} else {
+		erpnext.toggle_naming_series();
+	}
+
 
 	if(!doc.__islocal && doc.show_in_website) {
 		cur_frm.appframe.add_button("View In Website", function() {
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js
index 53e82f9..73259e3 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.js
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.js
@@ -61,7 +61,7 @@
 
 	refresh: function() {
 		var me = this;
-		erpnext.hide_naming_series();
+		erpnext.toggle_naming_series();
 		this.toggle_related_fields(this.frm.doc);
 		this.toggle_enable_bom();
 		this.show_stock_ledger();
diff --git a/erpnext/support/doctype/newsletter/newsletter.js b/erpnext/support/doctype/newsletter/newsletter.js
index 911cb39..6ea4926 100644
--- a/erpnext/support/doctype/newsletter/newsletter.js
+++ b/erpnext/support/doctype/newsletter/newsletter.js
@@ -13,7 +13,7 @@
 }
 
 cur_frm.cscript.refresh = function(doc) {
-	erpnext.hide_naming_series();
+	erpnext.toggle_naming_series();
 	if(!doc.__islocal && !cint(doc.email_sent) && !doc.__unsaved
 			&& inList(frappe.boot.user.can_write, doc.doctype)) {
 		cur_frm.add_custom_button(__('Send'), function() {
diff --git a/erpnext/support/doctype/support_ticket/support_ticket.js b/erpnext/support/doctype/support_ticket/support_ticket.js
index d09d7d6..0144d14 100644
--- a/erpnext/support/doctype/support_ticket/support_ticket.js
+++ b/erpnext/support/doctype/support_ticket/support_ticket.js
@@ -17,7 +17,7 @@
 	},
 	
 	refresh: function(doc) {
-		erpnext.hide_naming_series();
+		erpnext.toggle_naming_series();
 		cur_frm.cscript.make_listing(doc);
 		if(!doc.__islocal) {
 			if(cur_frm.fields_dict.status.get_status()=="Write") {