From 3f4885e3423c82a745fee4f4d87d6992f962b22f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 2 Sep 2014 19:59:20 +0530 Subject: [PATCH] repost stock reconciliation --- .../v4_2/repost_stock_reconciliation.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 erpnext/patches/v4_2/repost_stock_reconciliation.py diff --git a/erpnext/patches/v4_2/repost_stock_reconciliation.py b/erpnext/patches/v4_2/repost_stock_reconciliation.py new file mode 100644 index 0000000000..eb4de53a01 --- /dev/null +++ b/erpnext/patches/v4_2/repost_stock_reconciliation.py @@ -0,0 +1,31 @@ +# 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 +import json + +def execute(): + existing_allow_negative_stock = frappe.db.get_default("allow_negative_stock") + frappe.db.set_default("allow_negative_stock", 1) + + head_row = ["Item Code", "Warehouse", "Quantity", "Valuation Rate"] + stock_reco_to_be_reposted = [] + for d in frappe.db.sql("""select name, reconciliation_json from `tabStock Reconciliation` + where docstatus=1 and creation > '2014-03-01'""", as_dict=1): + data = json.loads(d.reconciliation_json) + for row in data[data.index(head_row)+1:]: + if row[3] in ["", None]: + stock_reco_to_be_reposted.append(d.name) + break + + for dn in stock_reco_to_be_reposted: + reco = frappe.get_doc("Stock Reconciliation", dn) + reco.docstatus = 2 + reco.on_cancel() + + reco.docstatus = 1 + reco.validate() + reco.on_submit() + + frappe.db.set_default("allow_negative_stock", existing_allow_negative_stock)