Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.txt b/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.txt
index f076063..d5294a3 100644
--- a/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.txt
+++ b/accounts/doctype/sales_taxes_and_charges/sales_taxes_and_charges.txt
@@ -1,8 +1,8 @@
 [
  {
-  "creation": "2013-01-10 16:34:09", 
+  "creation": "2013-01-24 11:03:30", 
   "docstatus": 0, 
-  "modified": "2013-01-23 17:11:18", 
+  "modified": "2013-01-24 14:15:49", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -161,7 +161,7 @@
   "fieldname": "included_in_print_rate", 
   "fieldtype": "Check", 
   "label": "Is this Tax included in Basic Rate?", 
-  "no_copy": 1, 
+  "no_copy": 0, 
   "print_hide": 1, 
   "report_hide": 1, 
   "width": "150px"
diff --git a/selling/doctype/customer/customer.py b/selling/doctype/customer/customer.py
index 8218b19..6aab938 100644
--- a/selling/doctype/customer/customer.py
+++ b/selling/doctype/customer/customer.py
@@ -172,6 +172,8 @@
 				pass
 
 	def on_update(self):
+		self.validate_name_with_customer_group()
+		
 		self.update_lead_status()
 		# create account head
 		self.create_account_head()
@@ -179,6 +181,12 @@
 		self.update_credit_days_limit()
 		#create address and contact from lead
 		self.create_lead_address_contact()
+		
+	def validate_name_with_customer_group(self):
+		if webnotes.conn.exists("Customer Group", self.doc.name):
+			webnotes.msgprint("An Customer Group exists with same name (%s), \
+				please change the Customer name or rename the Customer Group" % 
+				self.doc.name, raise_exception=1)
 
 	def delete_customer_address(self):
 		for rec in sql("select * from `tabAddress` where customer='%s'" %(self.doc.name), as_dict=1):
diff --git a/selling/page/sales_browser/sales_browser.py b/selling/page/sales_browser/sales_browser.py
index 45ca1d2..5b5e4b8 100644
--- a/selling/page/sales_browser/sales_browser.py
+++ b/selling/page/sales_browser/sales_browser.py
@@ -18,12 +18,16 @@
 		
 @webnotes.whitelist()
 def add_node():
-	from webnotes.model.doc import Document
+	# from webnotes.model.doc import Document
 	ctype = webnotes.form_dict.get('ctype')
 	parent_field = 'parent_' + ctype.lower().replace(' ', '_')
-
-	d = Document(ctype)
-	d.fields[ctype.lower().replace(' ', '_') + '_name'] = webnotes.form_dict['name_field']
-	d.fields[parent_field] = webnotes.form_dict['parent']
-	d.is_group = webnotes.form_dict['is_group']
-	d.save()
\ No newline at end of file
+	name_field = ctype.lower().replace(' ', '_') + '_name'
+	
+	doclist = [{
+		"doctype": ctype,
+		"__islocal": 1,
+		name_field: webnotes.form_dict['name_field'],
+		parent_field: webnotes.form_dict['parent'],
+		"is_group": webnotes.form_dict['is_group']
+	}]
+	webnotes.model_wrapper(doclist).save()
\ No newline at end of file
diff --git a/setup/doctype/customer_group/customer_group.py b/setup/doctype/customer_group/customer_group.py
index f13690d..a3baaa9 100644
--- a/setup/doctype/customer_group/customer_group.py
+++ b/setup/doctype/customer_group/customer_group.py
@@ -37,6 +37,15 @@
 				To untrash please go to Setup -> Recycle Bin.""" % 
 				(self.doc.customer_group_name), raise_exception = 1)		
 
+	def on_update(self):
+		self.validate_name_with_customer()
+		
+	def validate_name_with_customer(self):
+		if webnotes.conn.exists("Customer", self.doc.name):
+			webnotes.msgprint("An Customer exists with same name (%s), \
+				please change the Customer Group name or rename the Customer" % 
+				self.doc.name, raise_exception=1)
+
 	def on_trash(self):
 		cust = sql("select name from `tabCustomer` where ifnull(customer_group, '') = %s", 
 		 	self.doc.name)
diff --git a/setup/doctype/item_group/item_group.py b/setup/doctype/item_group/item_group.py
index 5fc5e91..32c5d52 100644
--- a/setup/doctype/item_group/item_group.py
+++ b/setup/doctype/item_group/item_group.py
@@ -24,10 +24,13 @@
 	def __init__(self, doc, doclist=[]):
 		self.doc = doc
 		self.doclist = doclist
-		self.nsm_parent_field = 'parent_item_group';
-	
+		self.nsm_parent_field = 'parent_item_group'
+		
 	def on_update(self):
 		super(DocType, self).on_update()
+		
+		self.validate_name_with_item()
+		
 		if self.doc.show_in_website:
 			# webpage updates
 			from website.utils import update_page_name
@@ -42,7 +45,12 @@
 			
 			from website.helpers.product import invalidate_cache_for
 			invalidate_cache_for(self.doc.name)
-			
+		
+	def validate_name_with_item(self):
+		if webnotes.conn.exists("Item", self.doc.name):
+			webnotes.msgprint("An item exists with same name (%s), please change the \
+				item group name or rename the item" % self.doc.name, raise_exception=1)
+	
 	def prepare_template_args(self):
 		from website.helpers.product import get_product_list_for_group, \
 			get_parent_item_groups, get_group_item_count
diff --git a/stock/doctype/item/item.py b/stock/doctype/item/item.py
index 748f01a..eab977b 100644
--- a/stock/doctype/item/item.py
+++ b/stock/doctype/item/item.py
@@ -18,9 +18,8 @@
 import webnotes
 
 from webnotes.utils import cstr, flt
-from webnotes.model import db_exists
 from webnotes.model.doc import addchild
-from webnotes.model.wrapper import getlist, copy_doclist
+from webnotes.model.wrapper import getlist
 from webnotes import msgprint
 
 sql = webnotes.conn.sql
@@ -38,6 +37,8 @@
 		return ret
 
 	def on_update(self):
+		self.validate_name_with_item_group()
+		
 		if self.doc.show_in_website:
 			# webpage updates
 			self.update_website()
@@ -62,8 +63,6 @@
 				if flt(d.conversion_factor) != 1:
 					msgprint("Conversion Factor of UOM : %s should be equal to 1. As UOM : %s is Stock UOM of Item: %s." % ( cstr(d.uom), cstr(d.uom), cstr(self.doc.name)))
 					raise Exception
-				# else set uom_exist as true
-				uom_exist='true'
 			elif cstr(d.uom) != cstr(self.doc.stock_uom) and flt(d.conversion_factor) == 1:
 				msgprint("Conversion Factor of UOM : %s should not be equal to 1. As UOM : %s is not Stock UOM of Item: %s." % ( cstr(d.uom), cstr(d.uom), cstr(self.doc.name)))
 				raise Exception
@@ -75,6 +74,12 @@
 			child.conversion_factor = 1
 			child.save()
 
+	def validate_name_with_item_group(self):
+		if webnotes.conn.exists("Item Group", self.doc.name):
+			webnotes.msgprint("An item group exists with same name (%s), \
+				please change the item name or rename the item group" % 
+				self.doc.name, raise_exception=1)
+
 	def update_website(self):
 		from website.utils import update_page_name
 		if self.doc.name==self.doc.item_name:
@@ -179,7 +184,7 @@
 
 		if self.doc.name:
 			self.old_page_name = webnotes.conn.get_value('Item', self.doc.name, 'page_name')
-		
+					
 	def check_non_asset_warehouse(self):
 		if self.doc.is_asset_item == "Yes":
 			existing_qty = sql("select t1.warehouse, t1.actual_qty from tabBin t1, tabWarehouse t2 where t1.item_code=%s and (t2.warehouse_type!='Fixed Asset' or t2.warehouse_type is null) and t1.warehouse=t2.name and t1.actual_qty > 0", self.doc.name)