From 7a31f6aaca9a41e963535f311e7e56e86c6a0a24 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 9 Mar 2015 16:31:11 +0530 Subject: [PATCH 1/2] repost reserved qty if negative --- erpnext/patches.txt | 1 + erpnext/patches/v4_2/repost_reserved_qty.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 erpnext/patches/v4_2/repost_reserved_qty.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 3e4bc81a12..820403706c 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -94,3 +94,4 @@ erpnext.patches.v4_2.discount_amount erpnext.patches.v4_2.update_landed_cost_voucher erpnext.patches.v4_2.set_item_has_batch erpnext.patches.v4_2.update_stock_uom_for_dn_in_sle +erpnext.patches.v4_2.repost_reserved_qty \ No newline at end of file diff --git a/erpnext/patches/v4_2/repost_reserved_qty.py b/erpnext/patches/v4_2/repost_reserved_qty.py new file mode 100644 index 0000000000..04dfb77bfa --- /dev/null +++ b/erpnext/patches/v4_2/repost_reserved_qty.py @@ -0,0 +1,12 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe +from erpnext.utilities.repost_stock import update_bin_qty, get_reserved_qty + +def execute(): + for item_code, warehouse in frappe.db.sql("select item_code, warehouse from tabBin where ifnull(reserved_qty, 0) < 0"): + update_bin_qty(item_code, warehouse, { + "reserved_qty": get_reserved_qty(item_code, warehouse) + }) \ No newline at end of file From 11498cac94215a1e0424da4aaf196c987d5629c4 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 9 Mar 2015 18:28:35 +0530 Subject: [PATCH 2/2] Repost sle for si without warehouse --- erpnext/patches.txt | 3 +- .../repost_sle_for_si_with_no_warehouse.py | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 erpnext/patches/v4_2/repost_sle_for_si_with_no_warehouse.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 820403706c..e3437a56f5 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -94,4 +94,5 @@ erpnext.patches.v4_2.discount_amount erpnext.patches.v4_2.update_landed_cost_voucher erpnext.patches.v4_2.set_item_has_batch erpnext.patches.v4_2.update_stock_uom_for_dn_in_sle -erpnext.patches.v4_2.repost_reserved_qty \ No newline at end of file +erpnext.patches.v4_2.repost_reserved_qty +erpnext.patches.v4_2.repost_sle_for_si_with_no_warehouse \ No newline at end of file diff --git a/erpnext/patches/v4_2/repost_sle_for_si_with_no_warehouse.py b/erpnext/patches/v4_2/repost_sle_for_si_with_no_warehouse.py new file mode 100644 index 0000000000..44bec0091a --- /dev/null +++ b/erpnext/patches/v4_2/repost_sle_for_si_with_no_warehouse.py @@ -0,0 +1,34 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe +from erpnext.stock.stock_ledger import NegativeStockError + +def execute(): + si_list = frappe.db.sql("""select distinct si.name + from `tabSales Invoice Item` si_item, `tabSales Invoice` si + where si.name = si_item.parent and si.modified > '2015-02-16' and si.docstatus=1 + and ifnull(si_item.warehouse, '') = '' and ifnull(si.update_stock, 0) = 1 + order by posting_date, posting_time""", as_dict=1) + + failed_list = [] + for si in si_list: + try: + si_doc = frappe.get_doc("Sales Invoice", si.name) + si_doc.docstatus = 2 + si_doc.on_cancel() + + si_doc.docstatus = 1 + si_doc.set_missing_item_details() + si_doc.on_submit() + frappe.db.commit() + except: + failed_list.append(si.name) + frappe.local.stockledger_exceptions = None + frappe.db.rollback() + + print "Failed to repost: ", failed_list + + + \ No newline at end of file