[naming series] create, remove Property Setters to set naming fixes webnotes/erpnext#854
diff --git a/buying/doctype/buying_settings/buying_settings.py b/buying/doctype/buying_settings/buying_settings.py
index 3f4f96d..efca339 100644
--- a/buying/doctype/buying_settings/buying_settings.py
+++ b/buying/doctype/buying_settings/buying_settings.py
@@ -13,4 +13,7 @@
 	def validate(self):
 		for key in ["supplier_type", "supp_master_name", "maintain_same_rate", "buying_price_list"]:
 			webnotes.conn.set_default(key, self.doc.fields.get(key, ""))
-	
\ No newline at end of file
+
+		from setup.doctype.naming_series.naming_series import set_by_naming_series
+		set_by_naming_series("Supplier", "supplier_name", 
+			self.doc.get("supp_master_name")=="Naming Series", hide_name_field=False)
diff --git a/buying/doctype/supplier/supplier.js b/buying/doctype/supplier/supplier.js
index 75542c8..ebe4e0e 100644
--- a/buying/doctype/supplier/supplier.js
+++ b/buying/doctype/supplier/supplier.js
@@ -9,10 +9,7 @@
 
 cur_frm.cscript.refresh = function(doc,dt,dn) {
 	cur_frm.cscript.make_dashboard(doc);
-	if(sys_defaults.supp_master_name == 'Supplier Name')
-		hide_field('naming_series');
-	else
-		unhide_field('naming_series'); 
+	erpnext.hide_naming_series();
     
 	if(doc.__islocal){
     	hide_field(['address_html','contact_html']); 
diff --git a/hr/doctype/employee/employee.py b/hr/doctype/employee/employee.py
index b46123a..56dfb35 100644
--- a/hr/doctype/employee/employee.py
+++ b/hr/doctype/employee/employee.py
@@ -20,12 +20,8 @@
 			webnotes.throw(_("Please setup Employee Naming System in Human Resource > HR Settings"))
 		else:
 			if naming_method=='Naming Series':
-				if not self.doc.naming_series:
-					webnotes.throw(_("Please select Naming Neries"))
 				self.doc.name = make_autoname(self.doc.naming_series + '.####')
 			elif naming_method=='Employee Number':
-				if not self.doc.employee_number:
-					webnotes.throw(_("Please enter Employee Number"))
 				self.doc.name = self.doc.employee_number
 
 		self.doc.employee = self.doc.name
diff --git a/hr/doctype/hr_settings/hr_settings.py b/hr/doctype/hr_settings/hr_settings.py
index 101905c..20edd16 100644
--- a/hr/doctype/hr_settings/hr_settings.py
+++ b/hr/doctype/hr_settings/hr_settings.py
@@ -13,12 +13,18 @@
 		self.doc, self.doclist = d, dl
 		
 	def validate(self):
-		self.original_stop_birthday_reminders = cint(webnotes.conn.get_value("HR Settings", 
-			None, "stop_birthday_reminders"))
+		self.update_birthday_reminders()
+
+		from setup.doctype.naming_series.naming_series import set_by_naming_series
+		set_by_naming_series("Employee", "employee_number", 
+			self.doc.get("emp_created_by")=="Naming Series", hide_name_field=True)
 			
-	def on_update(self):
+	def update_birthday_reminders(self):
+		original_stop_birthday_reminders = cint(webnotes.conn.get_value("HR Settings", 
+			None, "stop_birthday_reminders"))
+
 		# reset birthday reminders
-		if cint(self.doc.stop_birthday_reminders) != self.original_stop_birthday_reminders:
+		if cint(self.doc.stop_birthday_reminders) != original_stop_birthday_reminders:
 			webnotes.conn.sql("""delete from `tabEvent` where repeat_on='Every Year' and ref_type='Employee'""")
 		
 			if not self.doc.stop_birthday_reminders:
diff --git a/patches/october_2013/p09_update_naming_series_settings.py b/patches/october_2013/p09_update_naming_series_settings.py
new file mode 100644
index 0000000..57b48da
--- /dev/null
+++ b/patches/october_2013/p09_update_naming_series_settings.py
@@ -0,0 +1,10 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import webnotes
+
+def execute():
+	# reset property setters for series
+	for name in ("Stock Settings", "Selling Settings", "Buying Settings", "HR Settings"):
+		webnotes.bean(name, name).save()
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index 78dc155..5e03664 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -228,4 +228,5 @@
 	"patches.october_2013.repost_planned_qty",
 	"patches.october_2013.p06_rename_packing_list_doctype",
 	"execute:webnotes.delete_doc('DocType', 'Sales Common')",
+	"patches.october_2013.p09_update_naming_series_settings",
 ]
\ No newline at end of file
diff --git a/public/js/utils.js b/public/js/utils.js
index 6879b69..ddeca26 100644
--- a/public/js/utils.js
+++ b/public/js/utils.js
@@ -13,7 +13,7 @@
 	},
 	
 	hide_naming_series: function() {
-		if(cur_frm.fields_dict.naming_series) {
+		if(cur_frm.fields_dict.naming_series && !wn.meta.get_docfield(cur_frm.doctype, "naming_series")) {
 			cur_frm.toggle_display("naming_series", cur_frm.doc.__islocal?true:false);
 		}
 	},
diff --git a/selling/doctype/customer/customer.js b/selling/doctype/customer/customer.js
index a38ab9c..a703eed 100644
--- a/selling/doctype/customer/customer.js
+++ b/selling/doctype/customer/customer.js
@@ -20,10 +20,7 @@
 
 cur_frm.cscript.refresh = function(doc,dt,dn) {
 	cur_frm.cscript.setup_dashboard(doc);
-	if(sys_defaults.cust_master_name == 'Customer Name')
-		hide_field('naming_series');
-	else
-		unhide_field('naming_series');
+	erpnext.hide_naming_series();
 
 	if(doc.__islocal){		
 		hide_field(['address_html','contact_html']);
diff --git a/selling/doctype/customer/customer.txt b/selling/doctype/customer/customer.txt
index b25c0bd..5d3a508 100644
--- a/selling/doctype/customer/customer.txt
+++ b/selling/doctype/customer/customer.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-06-11 14:26:44", 
   "docstatus": 0, 
-  "modified": "2013-09-10 10:50:50", 
+  "modified": "2013-10-18 16:49:20", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -50,6 +50,16 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "naming_series", 
+  "fieldtype": "Select", 
+  "label": "Document Numbering Series", 
+  "no_copy": 1, 
+  "options": "\nCUST\nCUSTMUM", 
+  "permlevel": 0, 
+  "print_hide": 0
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "customer_name", 
   "fieldtype": "Data", 
   "hidden": 0, 
@@ -77,16 +87,6 @@
   "reqd": 1
  }, 
  {
-  "doctype": "DocField", 
-  "fieldname": "naming_series", 
-  "fieldtype": "Select", 
-  "label": "Document Numbering Series", 
-  "no_copy": 1, 
-  "options": "\nCUST\nCUSTMUM", 
-  "permlevel": 0, 
-  "print_hide": 0
- }, 
- {
   "description": "Fetch lead which will be converted into customer.", 
   "doctype": "DocField", 
   "fieldname": "lead_name", 
diff --git a/selling/doctype/selling_settings/selling_settings.py b/selling/doctype/selling_settings/selling_settings.py
index 9386652..620721d 100644
--- a/selling/doctype/selling_settings/selling_settings.py
+++ b/selling/doctype/selling_settings/selling_settings.py
@@ -14,3 +14,7 @@
 		for key in ["cust_master_name", "customer_group", "territory", "maintain_same_sales_rate",
 			"editable_price_list_rate", "selling_price_list"]:
 				webnotes.conn.set_default(key, self.doc.fields.get(key, ""))
+
+		from setup.doctype.naming_series.naming_series import set_by_naming_series
+		set_by_naming_series("Customer", "customer_name", 
+			self.doc.get("cust_master_name")=="Naming Series", hide_name_field=False)
diff --git a/setup/doctype/naming_series/naming_series.py b/setup/doctype/naming_series/naming_series.py
index 4e85b15..527ec6e 100644
--- a/setup/doctype/naming_series/naming_series.py
+++ b/setup/doctype/naming_series/naming_series.py
@@ -134,3 +134,20 @@
 			msgprint("Series Updated Successfully")
 		else:
 			msgprint("Please select prefix first")
+
+def set_by_naming_series(doctype, fieldname, naming_series, hide_name_field=True):
+	from core.doctype.property_setter.property_setter import make_property_setter
+	if naming_series:
+		make_property_setter(doctype, "naming_series", "hidden", 0, "Check")
+		make_property_setter(doctype, "naming_series", "reqd", 1, "Check")
+		if hide_name_field:
+			make_property_setter(doctype, fieldname, "reqd", 0, "Check")
+			make_property_setter(doctype, fieldname, "hidden", 1, "Check")
+	else:
+		make_property_setter(doctype, "naming_series", "reqd", 0, "Check")
+		make_property_setter(doctype, "naming_series", "hidden", 1, "Check")
+		if hide_name_field:
+			make_property_setter(doctype, fieldname, "hidden", 0, "Check")
+			make_property_setter(doctype, fieldname, "reqd", 1, "Check")
+		
+	
\ No newline at end of file
diff --git a/stock/doctype/item/item.js b/stock/doctype/item/item.js
index d0b8492..daa8e23 100644
--- a/stock/doctype/item/item.js
+++ b/stock/doctype/item/item.js
@@ -6,11 +6,7 @@
 	// read only if any stock ledger entry exists
 
 	cur_frm.cscript.make_dashboard()
-
-	cur_frm.toggle_display("naming_series", sys_defaults.item_naming_by=="Naming Series" 
-		&& doc.__islocal)
-	cur_frm.toggle_display("item_code", sys_defaults.item_naming_by!="Naming Series"
-		&& doc.__islocal)
+	erpnext.hide_naming_series();
 		
 	if(!doc.__islocal && doc.show_in_website) {
 		cur_frm.add_custom_button("View In Website", function() {
diff --git a/stock/doctype/stock_settings/stock_settings.py b/stock/doctype/stock_settings/stock_settings.py
index bc7dcba..e457257 100644
--- a/stock/doctype/stock_settings/stock_settings.py
+++ b/stock/doctype/stock_settings/stock_settings.py
@@ -6,6 +6,7 @@
 from __future__ import unicode_literals
 import webnotes
 
+
 class DocType:
 	def __init__(self, d, dl):
 		self.doc, self.doclist = d, dl
@@ -14,3 +15,8 @@
 		for key in ["item_naming_by", "item_group", "stock_uom", 
 			"allow_negative_stock"]:
 			webnotes.conn.set_default(key, self.doc.fields.get(key, ""))
+			
+		from setup.doctype.naming_series.naming_series import set_by_naming_series
+		set_by_naming_series("Item", "item_code", 
+			self.doc.get("item_naming_by")=="Naming Series", hide_name_field=True)
+