From 6656acff529ed2a06035c1ae042e50e4df22b269 Mon Sep 17 00:00:00 2001
From: Nabin Hait <nabinhait@gmail.com>
Date: Thu, 12 Sep 2013 11:46:09 +0530
Subject: [PATCH 1/2] [minor] [fix] set stock uom in stock ledger entry through
 stock reconciliation

---
 patches/patch_list.py                                    | 1 +
 patches/september_2013/p03_update_stock_uom_in_sle.py    | 9 +++++++++
 stock/doctype/item/item.py                               | 1 -
 stock/doctype/stock_ledger_entry/stock_ledger_entry.py   | 7 +++++--
 .../doctype/stock_reconciliation/stock_reconciliation.py | 1 +
 5 files changed, 16 insertions(+), 3 deletions(-)
 create mode 100644 patches/september_2013/p03_update_stock_uom_in_sle.py

diff --git a/patches/patch_list.py b/patches/patch_list.py
index 3c13e0eb47..b57efcbac9 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -263,4 +263,5 @@ patch_list = [
 	"patches.september_2013.p01_update_communication",
 	"execute:webnotes.reload_doc('setup', 'doctype', 'features_setup') # 2013-09-05",
 	"patches.september_2013.p02_fix_serial_no_status",
+	"patches.september_2013.p03_update_stock_uom_in_sle",
 ]
\ No newline at end of file
diff --git a/patches/september_2013/p03_update_stock_uom_in_sle.py b/patches/september_2013/p03_update_stock_uom_in_sle.py
new file mode 100644
index 0000000000..ba1ea8a2e9
--- /dev/null
+++ b/patches/september_2013/p03_update_stock_uom_in_sle.py
@@ -0,0 +1,9 @@
+# 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():
+	webnotes.conn.sql("""update `tabStock Ledger Entry` sle, tabItem i 
+		set sle.stock_uom = i.stock_uom 
+		where sle.item_code = i.name and ifnull(sle.stock_uom, '') = ''""")
\ No newline at end of file
diff --git a/stock/doctype/item/item.py b/stock/doctype/item/item.py
index 75e2b034a3..2c702a644e 100644
--- a/stock/doctype/item/item.py
+++ b/stock/doctype/item/item.py
@@ -70,7 +70,6 @@ class DocType(DocListController):
 			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
diff --git a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
index 2f365383fd..f8616c39a6 100644
--- a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
+++ b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
@@ -72,7 +72,7 @@ class DocType(DocListController):
 
 	def validate_item(self):
 		item_det = webnotes.conn.sql("""select name, has_batch_no, docstatus, 
-			is_stock_item, has_serial_no, serial_no_series 
+			is_stock_item, has_serial_no, serial_no_series, stock_uom 
 			from tabItem where name=%s""", 
 			self.doc.item_code, as_dict=True)[0]
 
@@ -88,7 +88,10 @@ class DocType(DocListController):
 			if not webnotes.conn.sql("""select name from `tabBatch` 
 				where item='%s' and name ='%s' and docstatus != 2""" % (self.doc.item_code, self.doc.batch_no)):
 				webnotes.throw("'%s' is not a valid Batch Number for Item '%s'" % (self.doc.batch_no, self.doc.item_code))
-	
+				
+		if not self.doc.stock_uom:
+			self.doc.stock_uom = item_det.stock_uom
+			
 		self.validate_serial_no(item_det)
 	
 	def validate_serial_no(self, item_det):
diff --git a/stock/doctype/stock_reconciliation/stock_reconciliation.py b/stock/doctype/stock_reconciliation/stock_reconciliation.py
index dbb0a348c3..da286d3c9d 100644
--- a/stock/doctype/stock_reconciliation/stock_reconciliation.py
+++ b/stock/doctype/stock_reconciliation/stock_reconciliation.py
@@ -243,6 +243,7 @@ class DocType(StockController):
 			"voucher_type": self.doc.doctype,
 			"voucher_no": self.doc.name,
 			"company": self.doc.company,
+			"stock_uom": webnotes.conn.get_value("Item", row.item_code, "stock_uom"),
 			"is_cancelled": "No",
 			"voucher_detail_no": row.voucher_detail_no,
 			"fiscal_year": self.doc.fiscal_year,

From 16447005bf6f51f883372758c2606ee0be1c0e3d Mon Sep 17 00:00:00 2001
From: Nabin Hait <nabinhait@gmail.com>
Date: Thu, 12 Sep 2013 16:58:54 +0530
Subject: [PATCH 2/2] [fix] [minor] fixes in old patch

---
 patches/december_2012/address_title.py | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/patches/december_2012/address_title.py b/patches/december_2012/address_title.py
index fc7d2baed1..13dd74d896 100644
--- a/patches/december_2012/address_title.py
+++ b/patches/december_2012/address_title.py
@@ -9,9 +9,6 @@ def execute():
 	webnotes.conn.sql("""update tabAddress set address_title = customer_name where ifnull(customer_name,'')!=''""")
 	webnotes.conn.sql("""update tabAddress set address_title = supplier_name where ifnull(supplier_name,'')!=''""")
 	webnotes.conn.sql("""update tabAddress set address_title = sales_partner where ifnull(sales_partner,'')!=''""")
-
-	webnotes.reload_doc("website", "doctype", "product_settings")
-	webnotes.reset_perms("Product Settings")
 	
 	# move code to new doctype
 	webnotes.conn.set_value("Website Script", None, "javascript",