Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/home/page/latest_updates/latest_updates.js b/home/page/latest_updates/latest_updates.js
index 38c0026..910c1b1 100644
--- a/home/page/latest_updates/latest_updates.js
+++ b/home/page/latest_updates/latest_updates.js
@@ -1,4 +1,6 @@
 erpnext.updates = [
+	["17th May", ["Patch: Set Conversion Factor for purchase invoice item in all old records. And repost JV to book Stock Received But Not Billed account, if Auto Inventory Integration enabed."
+	]],
 	["2nd May", ["Buying: Warehouse must belong to same company as transaction",
 		"Price List: Added Currency Field. One price list can have only one currency",
 		"Item: Naming can now be by series or item code",
diff --git a/patches/may_2013/p01_conversion_factor_and_aii.py b/patches/may_2013/p01_conversion_factor_and_aii.py
new file mode 100644
index 0000000..89d82e0
--- /dev/null
+++ b/patches/may_2013/p01_conversion_factor_and_aii.py
@@ -0,0 +1,26 @@
+import webnotes
+from webnotes.utils import cint
+from accounts.utils import create_stock_in_hand_jv
+
+def execute():
+	webnotes.conn.auto_commit_on_many_writes = True
+	
+	aii_enabled = cint(webnotes.conn.get_value("Global Defaults", None, 
+		"auto_inventory_accounting"))
+	
+	if aii_enabled:
+		create_stock_in_hand_jv(reverse = True)
+	
+	webnotes.conn.sql("""update `tabPurchase Invoice Item` pi_item 
+		set conversion_factor = (select ifnull(if(conversion_factor=0, 1, conversion_factor), 1) 
+			from `tabUOM Conversion Detail` 
+			where parent = pi_item.item_code and uom = pi_item.uom
+		)
+		where ifnull(conversion_factor, 0)=0""")
+	
+	if aii_enabled:
+		create_stock_in_hand_jv()
+	
+	webnotes.conn.auto_commit_on_many_writes = False
+	
+	
\ No newline at end of file
diff --git a/patches/may_2013/repost_stock_for_no_posting_time.py b/patches/may_2013/repost_stock_for_no_posting_time.py
index 04ceae5..b4d52ec 100644
--- a/patches/may_2013/repost_stock_for_no_posting_time.py
+++ b/patches/may_2013/repost_stock_for_no_posting_time.py
@@ -29,6 +29,6 @@
 	    except:
 	        pass
 	    i += 1
-	    if i%100 == 0:
+	    if i%50 == 0:
 	        webnotes.conn.sql("commit")
 	        webnotes.conn.sql("start transaction")
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index c176a91..1610009 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -247,4 +247,5 @@
 	"patches.april_2013.rebuild_sales_browser",
 	"patches.april_2013.p08_price_list_country",
 	"patches.may_2013.repost_stock_for_no_posting_time",
+	"patches.may_2013.p01_conversion_factor_and_aii",
 ]
\ No newline at end of file