Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/accounts/doctype/journal_voucher/journal_voucher.txt b/accounts/doctype/journal_voucher/journal_voucher.txt
index 4fba94a..fdc27ea 100644
--- a/accounts/doctype/journal_voucher/journal_voucher.txt
+++ b/accounts/doctype/journal_voucher/journal_voucher.txt
@@ -2,11 +2,12 @@
  {
   "creation": "2013-03-25 10:53:52", 
   "docstatus": 0, 
-  "modified": "2013-08-08 14:21:56", 
+  "modified": "2013-09-10 14:59:41", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
  {
+  "allow_import": 1, 
   "autoname": "naming_series:", 
   "doctype": "DocType", 
   "icon": "icon-file-text", 
diff --git a/accounts/doctype/pos_setting/pos_setting.py b/accounts/doctype/pos_setting/pos_setting.py
index f805518..183ebbe 100755
--- a/accounts/doctype/pos_setting/pos_setting.py
+++ b/accounts/doctype/pos_setting/pos_setting.py
@@ -40,13 +40,15 @@
 			msgprint(_("Expense Account is mandatory"), raise_exception=1)
 
 	def validate_all_link_fields(self):
-		accounts = {"Account": [self.doc.cash_bank_account, self.doc.income_account, self.doc.expense_account], \
-			"Cost Center": [self.doc.cost_center], "Warehouse": [self.doc.warehouse]}
+		accounts = {"Account": [self.doc.cash_bank_account, self.doc.income_account, 
+			self.doc.expense_account], "Cost Center": [self.doc.cost_center], 
+			"Warehouse": [self.doc.warehouse]}
 		
 		for link_dt, dn_list in accounts.items():
 			for link_dn in dn_list:
-				if not webnotes.conn.exists({"doctype": link_dt, "company": self.doc.company, "name": link_dn}):
-					msgprint(link_dn +_(" does not belong to ") + self.doc.company)
+				if link_dn and not webnotes.conn.exists({"doctype": link_dt, 
+						"company": self.doc.company, "name": link_dn}):
+					webnotes.throw(link_dn +_(" does not belong to ") + self.doc.company)
 
 	def on_update(self):
 		webnotes.defaults.clear_default("is_pos")
diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js
index 1378fab..f224c35 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/accounts/doctype/sales_invoice/sales_invoice.js
@@ -62,8 +62,18 @@
 
 			cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
 
-			if(cint(doc.update_stock)!=1)
-				cur_frm.add_custom_button('Make Delivery', cur_frm.cscript['Make Delivery Note']);
+			if(cint(doc.update_stock)!=1) {
+				// show Make Delivery Note button only if Sales Invoice is not created from Delivery Note
+				var from_delivery_note = false;
+				from_delivery_note = cur_frm.get_doclist({parentfield: "entries"})
+					.some(function(item) { 
+						return item.delivery_note ? true : false; 
+					});
+				
+				if(!from_delivery_note)
+					cur_frm.add_custom_button('Make Delivery', cur_frm.cscript['Make Delivery Note']);
+			}
+				
 
 			if(doc.outstanding_amount!=0)
 				cur_frm.add_custom_button('Make Payment Entry', cur_frm.cscript.make_bank_voucher);
diff --git a/buying/doctype/supplier/supplier.txt b/buying/doctype/supplier/supplier.txt
index 50202dc..56336d4 100644
--- a/buying/doctype/supplier/supplier.txt
+++ b/buying/doctype/supplier/supplier.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-01-10 16:34:11", 
   "docstatus": 0, 
-  "modified": "2013-09-02 16:25:44", 
+  "modified": "2013-09-10 10:53:50", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -137,13 +137,15 @@
   "fieldname": "communication_history", 
   "fieldtype": "Section Break", 
   "label": "Communication History", 
-  "options": "icon-comments"
+  "options": "icon-comments", 
+  "print_hide": 1
  }, 
  {
   "doctype": "DocField", 
   "fieldname": "communication_html", 
   "fieldtype": "HTML", 
-  "label": "Communication HTML"
+  "label": "Communication HTML", 
+  "print_hide": 1
  }, 
  {
   "doctype": "DocField", 
@@ -210,7 +212,8 @@
   "fieldtype": "Table", 
   "hidden": 1, 
   "label": "Communications", 
-  "options": "Communication"
+  "options": "Communication", 
+  "print_hide": 1
  }, 
  {
   "cancel": 0, 
diff --git a/hr/doctype/job_applicant/job_applicant.txt b/hr/doctype/job_applicant/job_applicant.txt
index 62b1d80..d795fa8 100644
--- a/hr/doctype/job_applicant/job_applicant.txt
+++ b/hr/doctype/job_applicant/job_applicant.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-01-29 19:25:37", 
   "docstatus": 0, 
-  "modified": "2013-09-02 16:26:23", 
+  "modified": "2013-09-10 10:51:51", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -95,7 +95,8 @@
   "fieldtype": "Table", 
   "hidden": 1, 
   "label": "Communications", 
-  "options": "Communication"
+  "options": "Communication", 
+  "print_hide": 1
  }, 
  {
   "doctype": "DocPerm"
diff --git a/selling/doctype/customer/customer.txt b/selling/doctype/customer/customer.txt
index 94bd8fc..b25c0bd 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-02 16:25:13", 
+  "modified": "2013-09-10 10:50:50", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -195,14 +195,16 @@
   "fieldtype": "Section Break", 
   "label": "Communication History", 
   "options": "icon-comments", 
-  "permlevel": 0
+  "permlevel": 0, 
+  "print_hide": 1
  }, 
  {
   "doctype": "DocField", 
   "fieldname": "communication_html", 
   "fieldtype": "HTML", 
   "label": "Communication HTML", 
-  "permlevel": 0
+  "permlevel": 0, 
+  "print_hide": 1
  }, 
  {
   "doctype": "DocField", 
@@ -355,7 +357,8 @@
   "hidden": 1, 
   "label": "Communications", 
   "options": "Communication", 
-  "permlevel": 0
+  "permlevel": 0, 
+  "print_hide": 1
  }, 
  {
   "amend": 0, 
diff --git a/selling/doctype/lead/lead.txt b/selling/doctype/lead/lead.txt
index 9402259..a429c96 100644
--- a/selling/doctype/lead/lead.txt
+++ b/selling/doctype/lead/lead.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-04-10 11:45:37", 
   "docstatus": 0, 
-  "modified": "2013-09-02 17:25:59", 
+  "modified": "2013-09-10 10:52:20", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -159,7 +159,8 @@
   "fieldname": "communication_history", 
   "fieldtype": "Section Break", 
   "label": "Communication History", 
-  "options": "icon-comments"
+  "options": "icon-comments", 
+  "print_hide": 1
  }, 
  {
   "allow_on_submit": 0, 
@@ -168,7 +169,8 @@
   "fieldtype": "HTML", 
   "label": "Communication HTML", 
   "oldfieldname": "follow_up", 
-  "oldfieldtype": "Table"
+  "oldfieldtype": "Table", 
+  "print_hide": 1
  }, 
  {
   "doctype": "DocField", 
@@ -416,7 +418,8 @@
   "fieldtype": "Table", 
   "hidden": 1, 
   "label": "Communications", 
-  "options": "Communication"
+  "options": "Communication", 
+  "print_hide": 1
  }, 
  {
   "cancel": 1, 
diff --git a/selling/doctype/opportunity/opportunity.txt b/selling/doctype/opportunity/opportunity.txt
index 4ca1564..a904f56 100644
--- a/selling/doctype/opportunity/opportunity.txt
+++ b/selling/doctype/opportunity/opportunity.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-03-07 18:50:30", 
   "docstatus": 0, 
-  "modified": "2013-09-02 16:27:33", 
+  "modified": "2013-09-10 10:52:49", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -168,6 +168,7 @@
   "label": "Communication History", 
   "oldfieldtype": "Section Break", 
   "options": "icon-comments", 
+  "print_hide": 1, 
   "read_only": 0
  }, 
  {
@@ -178,6 +179,7 @@
   "label": "Communication HTML", 
   "oldfieldname": "follow_up", 
   "oldfieldtype": "Table", 
+  "print_hide": 1, 
   "read_only": 0
  }, 
  {
@@ -448,7 +450,8 @@
   "fieldtype": "Table", 
   "hidden": 1, 
   "label": "Communications", 
-  "options": "Communication"
+  "options": "Communication", 
+  "print_hide": 1
  }, 
  {
   "doctype": "DocPerm", 
diff --git a/selling/doctype/quotation/quotation.txt b/selling/doctype/quotation/quotation.txt
index 9d47259..3f97c98 100644
--- a/selling/doctype/quotation/quotation.txt
+++ b/selling/doctype/quotation/quotation.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-24 19:29:08", 
   "docstatus": 0, 
-  "modified": "2013-09-02 16:25:01", 
+  "modified": "2013-09-10 10:46:33", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -841,7 +841,8 @@
   "fieldtype": "Table", 
   "hidden": 1, 
   "label": "Communications", 
-  "options": "Communication"
+  "options": "Communication", 
+  "print_hide": 1
  }, 
  {
   "amend": 1, 
diff --git a/setup/doctype/sales_person/sales_person.txt b/setup/doctype/sales_person/sales_person.txt
index d78b5c8..037c6de 100644
--- a/setup/doctype/sales_person/sales_person.txt
+++ b/setup/doctype/sales_person/sales_person.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-01-10 16:34:24", 
   "docstatus": 0, 
-  "modified": "2013-09-02 16:26:54", 
+  "modified": "2013-09-10 10:53:28", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -166,7 +166,8 @@
   "fieldtype": "Table", 
   "hidden": 1, 
   "label": "Communications", 
-  "options": "Communication"
+  "options": "Communication", 
+  "print_hide": 1
  }, 
  {
   "cancel": 0, 
diff --git a/stock/doctype/delivery_note/delivery_note.js b/stock/doctype/delivery_note/delivery_note.js
index 063b258..80c2646 100644
--- a/stock/doctype/delivery_note/delivery_note.js
+++ b/stock/doctype/delivery_note/delivery_note.js
@@ -16,7 +16,17 @@
 	refresh: function(doc, dt, dn) {
 		this._super();
 		
-		if(!doc.__billing_complete && doc.docstatus==1) cur_frm.add_custom_button('Make Invoice', this.make_sales_invoice);
+		if(!doc.__billing_complete && doc.docstatus==1) {
+			// show Make Invoice button only if Delivery Note is not created from Sales Invoice
+			var from_sales_invoice = false;
+			from_sales_invoice = cur_frm.get_doclist({parentfield: "delivery_note_details"})
+				.some(function(item) { 
+					return item.prevdoc_doctype==="Sales Invoice" ? true : false; 
+				});
+			
+			if(!from_sales_invoice)
+				cur_frm.add_custom_button('Make Invoice', this.make_sales_invoice);
+		}
 	
 		if(flt(doc.per_installed, 2) < 100 && doc.docstatus==1) 
 			cur_frm.add_custom_button('Make Installation Note', this.make_installation_note);
diff --git a/stock/doctype/item/item.py b/stock/doctype/item/item.py
index e6c277e..75e2b03 100644
--- a/stock/doctype/item/item.py
+++ b/stock/doctype/item/item.py
@@ -30,8 +30,8 @@
 		
 		self.check_warehouse_is_set_for_stock_item()
 		self.check_stock_uom_with_bin()
-		self.validate_conversion_factor()
 		self.add_default_uom_in_conversion_factor_table()
+		self.validate_conversion_factor()
 		self.valiadte_item_type()
 		self.check_for_active_boms()
 		self.validate_price_lists()
@@ -59,15 +59,38 @@
 			ch = addchild(self.doc, 'uom_conversion_details', 'UOM Conversion Detail', self.doclist)
 			ch.uom = self.doc.stock_uom
 			ch.conversion_factor = 1
+			
+		for d in self.doclist.get({"parentfield": "uom_conversion_details"}):
+			if d.conversion_factor == 1 and d.uom != self.doc.stock_uom:
+				self.doclist.remove(d)
+				
 
 	def check_stock_uom_with_bin(self):
 		if not self.doc.fields.get("__islocal"):
-			bin = webnotes.conn.sql("select stock_uom from `tabBin` where item_code = %s", 
-				self.doc.name)
-			if self.doc.stock_uom and bin and cstr(bin[0][0]) \
-					and cstr(bin[0][0]) != cstr(self.doc.stock_uom):
-				msgprint(_("Please Update Stock UOM with the help of Stock UOM Replace Utility."), 
-					raise_exception=1)
+			matched=True
+			ref_uom = webnotes.conn.get_value("Stock Ledger Entry", 
+				{"item_code": self.doc.name, "is_cancelled": "No"}, "stock_uom")
+			
+			if ref_uom:
+				if cstr(ref_uom) != cstr(self.doc.stock_uom):
+					matched = False
+			else:
+				bin_list = webnotes.conn.sql("select * from tabBin where item_code=%s", 
+					self.doc.item_code, as_dict=1)
+				for bin in bin_list:
+					if bin.reserved_qty > 0 or bin.ordered_qty > 0 or bin.indented_qty > 0 \
+						or bin.planned_qty > 0 and cstr(bin.stock_uom) != cstr(self.doc.stock_uom):
+							matched = False
+							break
+						
+				if matched and bin_list:
+					webnotes.conn.sql("""update tabBin set stock_uom=%s where item_code=%s""",
+						(self.doc.stock_uom, self.doc.name))
+				
+			if not matched:
+				webnotes.throw(_("Default Unit of Measure can not be changed directly \
+					because you have already made some transaction(s) with another UOM.\n \
+					To change default UOM, use 'UOM Replace Utility' tool under Stock module."))
 	
 	def validate_conversion_factor(self):
 		check_list = []
diff --git a/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py b/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py
index 4e69a37..eff62f6 100644
--- a/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py
+++ b/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py
@@ -8,7 +8,7 @@
 from webnotes.model import db_exists
 from webnotes.model.bean import copy_doclist
 from webnotes.model.code import get_obj
-from webnotes import msgprint
+from webnotes import msgprint, _
 
 sql = webnotes.conn.sql
 
@@ -41,11 +41,11 @@
 			raise Exception
 			
 	def update_item_master(self):
-		# update stock uom in item master
-		sql("update `tabItem` set stock_uom = '%s' where name = '%s' " % (self.doc.new_stock_uom, self.doc.item_code))
+		item_bean = webnotes.bean("Item", self.doc.item_code)
+		item_bean.doc.stock_uom = self.doc.new_stock_uom
+		item_bean.save()
 		
-		# acknowledge user
-		msgprint("New Stock UOM : " + cstr(self.doc.new_stock_uom) + " updated in Item : " + cstr(self.doc.item_code))
+		msgprint(_("Default UOM updated in item ") + self.doc.item_code)
 		
 	def update_bin(self):
 		# update bin
@@ -80,20 +80,14 @@
 
 	# Update Stock UOM							
 	def update_stock_uom(self):
-		# validate mandatory
 		self.validate_mandatory()
 		self.validate_uom_integer_type()
 			
-		# update item master
 		self.update_item_master()
 		
-		# update stock ledger entry
 		self.update_stock_ledger_entry()
 		
-		# update bin
 		self.update_bin()
-
-		get_obj("Item", self.doc.item_code).on_update()
 		
 	def validate_uom_integer_type(self):
 		current_is_integer = webnotes.conn.get_value("UOM", self.doc.current_stock_uom, "must_be_whole_number")
diff --git a/support/doctype/support_ticket/support_ticket.txt b/support/doctype/support_ticket/support_ticket.txt
index 01d0e35..9f385b2 100644
--- a/support/doctype/support_ticket/support_ticket.txt
+++ b/support/doctype/support_ticket/support_ticket.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-02-01 10:36:25", 
   "docstatus": 0, 
-  "modified": "2013-09-02 16:24:24", 
+  "modified": "2013-09-10 10:54:02", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -267,7 +267,8 @@
   "fieldtype": "Table", 
   "hidden": 1, 
   "label": "Communications", 
-  "options": "Communication"
+  "options": "Communication", 
+  "print_hide": 1
  }, 
  {
   "cancel": 0, 
diff --git a/utilities/doctype/contact/contact.txt b/utilities/doctype/contact/contact.txt
index d3c7d88..92dcf2e 100644
--- a/utilities/doctype/contact/contact.txt
+++ b/utilities/doctype/contact/contact.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-01-10 16:34:32", 
   "docstatus": 0, 
-  "modified": "2013-09-02 16:26:13", 
+  "modified": "2013-09-10 10:50:27", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -101,13 +101,15 @@
   "fieldname": "sb00", 
   "fieldtype": "Section Break", 
   "label": "Communication History", 
-  "options": "icon-comments"
+  "options": "icon-comments", 
+  "print_hide": 1
  }, 
  {
   "doctype": "DocField", 
   "fieldname": "communication_html", 
   "fieldtype": "HTML", 
-  "label": "Communication HTML"
+  "label": "Communication HTML", 
+  "print_hide": 1
  }, 
  {
   "doctype": "DocField", 
@@ -231,7 +233,8 @@
   "fieldtype": "Table", 
   "hidden": 1, 
   "label": "Communications", 
-  "options": "Communication"
+  "options": "Communication", 
+  "print_hide": 1
  }, 
  {
   "cancel": 1, 
diff --git a/website/helpers/product.py b/website/helpers/product.py
index 8d817d0..031339a 100644
--- a/website/helpers/product.py
+++ b/website/helpers/product.py
@@ -11,7 +11,7 @@
 @webnotes.whitelist(allow_guest=True)
 def get_product_info(item_code):
 	"""get product price / stock info"""
-	if not webnotes.conn.get_default("shopping_cart_enabled"):
+	if not cint(webnotes.conn.get_default("shopping_cart_enabled")):
 		return {}
 	
 	cart_quotation = _get_cart_quotation()