brotherton-erpnext/patches/january_2013/stock_reconciliation_patch.py
2013-01-14 11:17:34 +05:30

45 lines
1.6 KiB
Python

import webnotes
def execute():
webnotes.reload_doc("stock", "doctype", "stock_ledger_entry")
rename_fields()
store_stock_reco_json()
def rename_fields():
args = [["Stock Ledger Entry", "bin_aqat", "qty_after_transaction"],
["Stock Ledger Entry", "fcfs_stack", "stock_queue"]]
for doctype, old_fieldname, new_fieldname in args:
webnotes.conn.sql("""update `tab%s` set `%s`=`%s`""" %
(doctype, new_fieldname, old_fieldname))
def store_stock_reco_json():
import os
import json
from webnotes.utils.datautils import read_csv_content
from webnotes.utils import get_base_path
files_path = os.path.join(get_base_path(), "public", "files")
list_of_files = os.listdir(files_path)
replaced_list_of_files = [f.replace("-", "") for f in list_of_files]
for reco, file_list in webnotes.conn.sql("""select name, file_list
from `tabStock Reconciliation`"""):
if file_list:
file_list = file_list.split("\n")
stock_reco_file = file_list[0].split(",")[1]
stock_reco_file_path = os.path.join(files_path, stock_reco_file)
if not os.path.exists(stock_reco_file_path):
if stock_reco_file in replaced_list_of_files:
stock_reco_file_path = os.path.join(files_path,
list_of_files[replaced_list_of_files.index(stock_reco_file)])
else:
stock_reco_file_path = ""
if stock_reco_file_path:
with open(stock_reco_file_path, "r") as open_reco_file:
content = open_reco_file.read()
content = read_csv_content(content)
webnotes.conn.set_value("Stock Reconciliation", reco, "reconciliation_json",
json.dumps(content, separators=(',', ': ')))