brotherton-erpnext/erpnext/patches/v4_2/repost_stock_reconciliation.py

32 lines
1.1 KiB
Python
Raw Normal View History

# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2014-09-02 14:29:20 +00:00
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
import json
def execute():
2014-11-26 10:05:08 +00:00
existing_allow_negative_stock = frappe.db.get_value("Stock Settings", None, "allow_negative_stock")
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
2014-09-02 14:29:20 +00:00
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()
2014-11-26 10:05:08 +00:00
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", existing_allow_negative_stock)