diff --git a/patches/december_2012/repost_ordered_qty.py b/patches/december_2012/repost_ordered_qty.py new file mode 100644 index 0000000000..c798b6cc7c --- /dev/null +++ b/patches/december_2012/repost_ordered_qty.py @@ -0,0 +1,17 @@ +def execute(): + import webnotes + from webnotes.utils import flt + bins = webnotes.conn.sql("select item_code, warehouse, name, ordered_qty from `tabBin`") + for d in bins: + ordered_qty = webnotes.conn.sql(""" + select sum(ifnull(po_item.qty, 0) - ifnull(po_item.received_qty, 0)) + from `tabPurchase Order Item` po_item, `tabPurchase Order` po + where po_item.parent = po.name and po.docstatus = 1 and po.status != 'Stopped' + and po_item.item_code = %s and po_item.warehouse = %s + """, (d[0], d[1])) + + if flt(d[3]) != flt(ordered_qty[0][0]): + print d[3], ordered_qty[0][0] + + webnotes.conn.sql("""update `tabBin` set ordered_qty = %s where name = %s""", + (ordered_qty and ordered_qty[0][0] or 0, d[2])) \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index 02f937abfd..c902e0daa4 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -709,4 +709,8 @@ patch_list = [ 'patch_module': 'patches.december_2012', 'patch_file': 'deprecate_tds', }, + { + 'patch_module': 'patches.december_2012', + 'patch_file': 'repost_ordered_qty', + }, ] \ No newline at end of file