From 0948b2a9d3604cb7755895a204b8a5415f38aec9 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 10 Oct 2013 19:04:18 +0530 Subject: [PATCH] [fix] [minor] repost order qty patch --- patches/december_2012/repost_ordered_qty.py | 25 +++++++++++-------- patches/patch_list.py | 1 + stock/doctype/serial_no/serial_no.py | 2 +- .../stock_ledger_entry/stock_ledger_entry.py | 6 ++--- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/patches/december_2012/repost_ordered_qty.py b/patches/december_2012/repost_ordered_qty.py index 2e3c690adf..e73b72663d 100644 --- a/patches/december_2012/repost_ordered_qty.py +++ b/patches/december_2012/repost_ordered_qty.py @@ -4,15 +4,18 @@ 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]): - 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 + for d in webnotes.conn.sql("select name, item_code, warehouse, ordered_qty from tabBin", + as_dict=1): + ordered_qty = webnotes.conn.sql(""" + select sum((po_item.qty - po_item.received_qty)*po_item.conversion_factor) + from `tabPurchase Order Item` po_item, `tabPurchase Order` po + where po_item.item_code=%s and po_item.warehouse=%s + and po_item.qty > po_item.received_qty and po_item.parent=po.name + and po.status!='Stopped' and po.docstatus=1""", (d.item_code, d.warehouse)) + + if flt(d.ordered_qty) != flt(ordered_qty[0][0]): + webnotes.conn.set_value("Bin", d.name, "ordered_qty", flt(ordered_qty[0][0])) + + webnotes.conn.sql("""update tabBin set projected_qty = actual_qty + planned_qty + + indented_qty + ordered_qty - reserved_qty where name = %s""", d.name) \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index f228acf97e..6a5d0f4f55 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -220,4 +220,5 @@ patch_list = [ "patches.september_2013.p04_unsubmit_serial_nos", "patches.september_2013.p05_fix_customer_in_pos", "patches.october_2013.fix_is_cancelled_in_sle", + "patches.october_2013.repost_ordered_qty", ] \ No newline at end of file diff --git a/stock/doctype/serial_no/serial_no.py b/stock/doctype/serial_no/serial_no.py index 3922878280..d806287ecb 100644 --- a/stock/doctype/serial_no/serial_no.py +++ b/stock/doctype/serial_no/serial_no.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import cint, getdate, nowdate, cstr, flt, add_days +from webnotes.utils import cint, getdate, cstr, flt, add_days import datetime from webnotes import msgprint, _, ValidationError diff --git a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py index 8fef889f72..bfb0f0aa92 100644 --- a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py +++ b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py @@ -3,8 +3,8 @@ from __future__ import unicode_literals import webnotes -from webnotes import _, msgprint -from webnotes.utils import cint, flt, getdate, cstr +from webnotes import msgprint +from webnotes.utils import flt, getdate from webnotes.model.controller import DocListController class DocType(DocListController): @@ -52,7 +52,7 @@ class DocType(DocListController): %(item_code)s at Warehouse %(warehouse)s \ as on %(posting_date)s %(posting_time)s""" % self.doc.fields) - sself.doc.fields.pop('batch_bal') + self.doc.fields.pop('batch_bal') def validate_mandatory(self): mandatory = ['warehouse','posting_date','voucher_type','voucher_no','actual_qty','company']