mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 19:29:10 +00:00
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
import webnotes
|
|
|
|
def execute():
|
|
webnotes.reload_doc("stock", "doctype", "stock_ledger_entry")
|
|
|
|
rename_fields()
|
|
move_remarks_to_comments()
|
|
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 move_remarks_to_comments():
|
|
from webnotes.utils import get_fullname
|
|
result = webnotes.conn.sql("""select name, remark, modified_by from `tabStock Reconciliation`
|
|
where ifnull(remark, '')!=''""")
|
|
fullname_map = {}
|
|
for reco, remark, modified_by in result:
|
|
webnotes.model_wrapper([{
|
|
"doctype": "Comment",
|
|
"comment": remark,
|
|
"comment_by": modified_by,
|
|
"comment_by_fullname": fullname_map.setdefault(modified_by, get_fullname(modified_by)),
|
|
"comment_doctype": "Stock Reconciliation",
|
|
"comment_docname": reco
|
|
}]).insert()
|
|
|
|
def store_stock_reco_json():
|
|
import os
|
|
import conf
|
|
import json
|
|
from webnotes.utils.datautils import read_csv_content
|
|
base_path = os.path.dirname(os.path.abspath(conf.__file__))
|
|
|
|
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 = os.path.join(base_path, "public", "files", stock_reco_file)
|
|
if os.path.exists(stock_reco_file):
|
|
with open(stock_reco_file, "r") as open_reco_file:
|
|
content = open_reco_file.read()
|
|
content = read_csv_content(content)
|
|
reconciliation_json = json.dumps(content, separators=(',', ': '))
|
|
webnotes.conn.sql("""update `tabStock Reconciliation`
|
|
set reconciliation_json=%s where name=%s""", (reconciliation_json, name))
|
|
|