From 26d46556a483bc17f37f166958257e9e6754ec15 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 9 Jan 2013 15:23:05 +0530 Subject: [PATCH] first cut error fixes --- .../repost_stock_for_posting_time.py | 6 ++---- .../repost_stock_due_to_wrong_packing_list.py | 8 ++++---- patches/september_2012/repost_stock.py | 7 +------ stock/doctype/bin/bin.py | 8 ++++---- stock/doctype/stock_entry/stock_entry.py | 19 +++++++++---------- .../stock_reconciliation.py | 8 ++++---- .../stock_uom_replace_utility.py | 2 +- stock/doctype/warehouse/warehouse.py | 7 +------ stock/stock_ledger.py | 9 +++++---- stock/utils.py | 9 ++++----- 10 files changed, 35 insertions(+), 48 deletions(-) diff --git a/patches/april_2012/repost_stock_for_posting_time.py b/patches/april_2012/repost_stock_for_posting_time.py index 2249ac190f6..d9cbbe5eb0a 100644 --- a/patches/april_2012/repost_stock_for_posting_time.py +++ b/patches/april_2012/repost_stock_for_posting_time.py @@ -8,8 +8,6 @@ def execute(): from stock.stock_ledger import update_entries_after for d in res: update_entries_after({ - item_code: d.item_code, - warehouse: d.warehouse, - posting_date: '2000-01-01', - posting_time: '12:01' + "item_code": d.item_code, + "warehouse": d.warehouse, }) diff --git a/patches/july_2012/repost_stock_due_to_wrong_packing_list.py b/patches/july_2012/repost_stock_due_to_wrong_packing_list.py index 10d4f500b97..81c64156440 100644 --- a/patches/july_2012/repost_stock_due_to_wrong_packing_list.py +++ b/patches/july_2012/repost_stock_due_to_wrong_packing_list.py @@ -82,10 +82,10 @@ def cleanup_wrong_sle(): webnotes.conn.sql("update `tabStock Ledger Entry` set is_cancelled = 'Yes' where name = %s", d[3]) create_comment(d[3]) update_entries_after({ - item_code: d[0], - warehouse: d[1], - posting_date: "2012-07-01", - posting_time: "12:05" + "item_code": d[0], + "warehouse": d[1], + "posting_date": "2012-07-01", + "posting_time": "12:05" }) def create_comment(dn): diff --git a/patches/september_2012/repost_stock.py b/patches/september_2012/repost_stock.py index 1fec9499ab5..972070137ae 100644 --- a/patches/september_2012/repost_stock.py +++ b/patches/september_2012/repost_stock.py @@ -22,12 +22,7 @@ def execute(): i=0 for d in res: try: - update_entries_after({ - item_code: d[0], - warehouse: d[1], - posting_date: "2000-01-01", - posting_time: "12:00" - }) + update_entries_after({ "item_code": d[0], "warehouse": d[1] }) except: pass i += 1 diff --git a/stock/doctype/bin/bin.py b/stock/doctype/bin/bin.py index c9bd9276491..c473a6c1db3 100644 --- a/stock/doctype/bin/bin.py +++ b/stock/doctype/bin/bin.py @@ -45,10 +45,10 @@ class DocType: if args.get("actual_qty"): # update valuation and qty after transaction for post dated entry update_entries_after({ - item_code: self.doc.item_code, - warehouse: self.doc.warehouse, - posting_date: args.get("posting_date"), - posting_time: args.get("posting_time") + "item_code": self.doc.item_code, + "warehouse": self.doc.warehouse, + "posting_date": args.get("posting_date"), + "posting_time": args.get("posting_time") }) def update_qty(self, args): diff --git a/stock/doctype/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py index ea44f1bbf05..e3cafa26d25 100644 --- a/stock/doctype/stock_entry/stock_entry.py +++ b/stock/doctype/stock_entry/stock_entry.py @@ -157,14 +157,13 @@ class DocType(TransactionBase): """get stock and incoming rate on posting date""" for d in getlist(self.doclist, 'mtn_details'): args = { - item_code: d.item_code, - warehouse: d.s_warehouse or d.t_warehouse, - posting_date: self.doc.posting_date, - posting_time: self.doc.posting_time, - qty: d.transfer_qty, - serial_no: d.serial_no, - bom_no: d.bom_no - + "item_code": d.item_code, + "warehouse": d.s_warehouse or d.t_warehouse, + "posting_date": self.doc.posting_date, + "posting_time": self.doc.posting_time, + "qty": d.transfer_qty, + "serial_no": d.serial_no, + "bom_no": d.bom_no } # get actual stock at source warehouse d.actual_qty = get_previous_sle(args).get("qty_after_transaction") or 0 @@ -308,8 +307,8 @@ class DocType(TransactionBase): import json args, actual_qty, in_rate = json.loads(args), 0, 0 args.update({ - posting_date: self.doc.posting_date, - posting_time: self.doc.posting_time + "posting_date": self.doc.posting_date, + "posting_time": self.doc.posting_time }) ret = { diff --git a/stock/doctype/stock_reconciliation/stock_reconciliation.py b/stock/doctype/stock_reconciliation/stock_reconciliation.py index b82a7f0dc17..021a833db8c 100644 --- a/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -205,10 +205,10 @@ class DocType(DocListController): # repost future entries for selected item_code, warehouse for entries in existing_entries: update_entries_after({ - item_code: entries.item_code, - warehouse: entries.warehouse, - posting_date: self.doc.posting_date, - posting_time: self.doc.posting_time + "item_code": entries.item_code, + "warehouse": entries.warehouse, + "posting_date": self.doc.posting_date, + "posting_time": self.doc.posting_time }) diff --git a/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py b/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py index 209bda5ff3b..9918010fd82 100644 --- a/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py +++ b/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py @@ -91,7 +91,7 @@ class DocType: if flt(self.doc.conversion_factor) != flt(1): wh = sql("select name from `tabWarehouse`") for w in wh: - update_entries_after({item_code: self.doc.item_code, warehouse: w[0]}) + update_entries_after({"item_code": self.doc.item_code, "warehouse": w[0]}) # acknowledge user msgprint("Item Valuation Updated Successfully.") diff --git a/stock/doctype/warehouse/warehouse.py b/stock/doctype/warehouse/warehouse.py index e65004bfe0a..775f0d03024 100644 --- a/stock/doctype/warehouse/warehouse.py +++ b/stock/doctype/warehouse/warehouse.py @@ -121,12 +121,7 @@ class DocType: if not warehouse: warehouse = self.doc.name - update_entries_after({ - item_code: item_code, - warehouse: warehouse, - posting_date: '1900-01-01', - posting_time = '10:00' - }) + update_entries_after({ "item_code": item_code, "warehouse": warehouse }) def repost_reserved_qty(self, bin): reserved_qty = webnotes.conn.sql(""" diff --git a/stock/stock_ledger.py b/stock/stock_ledger.py index d4475efa3a6..bb02f8cd33e 100644 --- a/stock/stock_ledger.py +++ b/stock/stock_ledger.py @@ -16,8 +16,9 @@ import webnotes from webnotes import msgprint, _ -from webnotes.utils import cint +from webnotes.utils import cint, flt, cstr from stock.utils import _msgprint, get_valuation_method +import json # future reposting @@ -67,7 +68,7 @@ def update_entries_after(args, verbose=1): qty_after_transaction += flt(sle.actual_qty) # get stock value - if serial_nos: + if sle.serial_nos: stock_value = qty_after_transaction * valuation_rate elif valuation_method == "Moving Average": stock_value = (qty_after_transaction > 0) and \ @@ -101,7 +102,7 @@ def get_sle_before_datetime(args): entries between the cancelled entries in the same time-bucket """ sle = get_stock_ledger_entries(args, - ["timestamp(posting_date, posting_time) < timestamp(%%(posting_date)s, %%(posting_time)s)"], + ["timestamp(posting_date, posting_time) < timestamp(%(posting_date)s, %(posting_time)s)"], "limit 1") return sle and sle[0] or webnotes._dict() @@ -109,7 +110,7 @@ def get_sle_before_datetime(args): def get_sle_after_datetime(args): """get Stock Ledger Entries after a particular datetime, for reposting""" return get_stock_ledger_entries(args, - ["timestamp(posting_date, posting_time) > timestamp(%%(posting_date)s, %%(posting_time)s)"]) + ["timestamp(posting_date, posting_time) > timestamp(%(posting_date)s, %(posting_time)s)"]) def get_stock_ledger_entries(args, conditions=None, limit=None): """get stock ledger entries filtered by specific posting datetime conditions""" diff --git a/stock/utils.py b/stock/utils.py index b3bf26af136..2c0eaefd30e 100644 --- a/stock/utils.py +++ b/stock/utils.py @@ -77,12 +77,11 @@ def get_previous_sle(args): "sle": "name of reference Stock Ledger Entry" } """ - if not args.get("posting_date"): - args["posting_date"] = "1900-01-01" - if not args.get("posting_time"): - args["posting_time"] = "12:00" + if not args.get("posting_date"): args["posting_date"] = "1900-01-01" + if not args.get("posting_time"): args["posting_time"] = "12:00" + if not args.get("sle"): args["sle"] = "" - sle = sql(""" + sle = webnotes.conn.sql(""" select * from `tabStock Ledger Entry` where item_code = %(item_code)s and warehouse = %(warehouse)s