brotherton-erpnext/erpnext/patches/v5_0/convert_stock_reconciliation.py

31 lines
894 B
Python
Raw Normal View History

2015-02-20 15:11:56 +05:30
import frappe, json
def execute():
# stock reco now amendable
frappe.db.sql("""update tabDocPerm set `amend` = 1 where parent='Stock Reconciliation' and submit = 1""")
2015-03-25 14:51:05 +05:30
frappe.reload_doc("stock", "doctype", "stock_reconciliation_item")
frappe.reload_doctype("Stock Reconciliation")
2015-02-20 15:11:56 +05:30
if frappe.db.has_column("Stock Reconciliation", "reconciliation_json"):
for sr in frappe.db.get_all("Stock Reconciliation", ["name"],
{"reconciliation_json": ["!=", ""]}):
2015-03-20 15:37:31 +05:30
start = False
2015-02-20 15:11:56 +05:30
sr = frappe.get_doc("Stock Reconciliation", sr.name)
2015-03-23 14:10:38 +05:30
for row in json.loads(sr.reconciliation_json):
2015-03-20 15:37:31 +05:30
if start:
2015-03-20 15:52:11 +05:30
sr.append("items", {
2015-03-23 14:10:38 +05:30
"item_code": row[0],
"warehouse": row[1],
2015-03-25 14:51:05 +05:30
"qty": row[2] if len(row) > 2 else None,
"valuation_rate": row[3] if len(row) > 3 else None
2015-03-20 15:52:11 +05:30
})
2015-03-20 15:37:31 +05:30
2015-03-23 14:10:38 +05:30
elif row[0]=="Item Code":
2015-03-20 15:37:31 +05:30
start = True
2015-02-20 15:11:56 +05:30
for item in sr.items:
item.db_update()