From b28d6dc617ab7ad851f46c2373582ef37433d5e6 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 6 Dec 2011 15:11:14 +0530 Subject: [PATCH] Repost stock patch --- erpnext/patches/repost_stock.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 erpnext/patches/repost_stock.py diff --git a/erpnext/patches/repost_stock.py b/erpnext/patches/repost_stock.py new file mode 100644 index 0000000000..680e06f435 --- /dev/null +++ b/erpnext/patches/repost_stock.py @@ -0,0 +1,22 @@ +def execute(): + import webnotes + sql = webnotes.conn.sql + from webnotes.model.code import get_obj + + # update incoming rate in serial nos + sr = sql("""select name, item_code, purchase_document_no from `tabSerial No` + where docstatus = 1 and purchase_document_type = 'Purchase Receipt'""") + for d in sr: + val_rate = sql("""select valuation_rate from `tabPurchase Receipt Detail` + where item_code = %s and parent = %s""", (d[1], d[2])) + sql("""update `tabSerial No` set purchase_rate = %s where name = %s""", + (val_rate and flt(val_rate[0][0]) or 0, d[0])) + + + # repost for all serialized item + bin = sql("""select t1.name from `tabBin` t1, tabItem t2 where t1.item_code = t2.name and ifnull(has_serial_no, 'No') = 'Yes'""") + for d in bin: + get_obj('Bin', d[0]).update_entries_after(posting_date = '2000-01-01', posting_time = '12:00') + sql("commit") + sql("start transaction") +