mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 05:39:12 +00:00
merge
This commit is contained in:
66
patches/january_2013/file_list_rename_returns.py
Normal file
66
patches/january_2013/file_list_rename_returns.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import webnotes
|
||||
from webnotes.utils import get_base_path
|
||||
import os
|
||||
|
||||
def execute():
|
||||
# find out when was the file list patch run
|
||||
res = webnotes.conn.sql("""select applied_on from `__PatchLog`
|
||||
where patch='patches.december_2012.file_list_rename' order by applied_on desc limit 1""")
|
||||
if res:
|
||||
patch_date = res[0][0].date()
|
||||
files_path = os.path.join(get_base_path(), "public", "files")
|
||||
|
||||
change_map = {}
|
||||
|
||||
file_data_list = webnotes.conn.sql("""select name, file_name from `tabFile Data`
|
||||
where date(modified) <= %s and ifnull(file_url, '')='' and name like "%%-%%" """,
|
||||
patch_date)
|
||||
|
||||
# print patch_date
|
||||
# print file_data_list
|
||||
# print files_path
|
||||
|
||||
for fid, file_name in file_data_list:
|
||||
if os.path.exists(os.path.join(files_path, fid)):
|
||||
new_fid, new_file_name = fid.replace("-", ""), file_name.replace("-", "")
|
||||
|
||||
try:
|
||||
webnotes.conn.sql("""update `tabFile Data`
|
||||
set name=%s, file_name=%s where name=%s""", (new_fid, new_file_name, fid))
|
||||
|
||||
os.rename(os.path.join(files_path, fid), os.path.join(files_path, new_fid))
|
||||
|
||||
change_map[",".join((file_name, fid))] = ",".join((new_file_name, new_fid))
|
||||
except Exception, e:
|
||||
# if duplicate entry, then dont update
|
||||
if e[0]!=1062:
|
||||
print webnotes.getTraceback()
|
||||
raise e
|
||||
|
||||
print change_map
|
||||
|
||||
changed_keys = change_map.keys()
|
||||
|
||||
for dt in webnotes.conn.sql("""select distinct parent from tabDocField
|
||||
where fieldname='file_list'"""):
|
||||
try:
|
||||
data = webnotes.conn.sql("""select name, file_list from `tab%s`
|
||||
where ifnull(file_list, '')!=''""" % dt[0])
|
||||
for name, file_list in data:
|
||||
new_file_list = []
|
||||
file_list = file_list.split("\n")
|
||||
for f in file_list:
|
||||
if f in changed_keys:
|
||||
new_file_list.append(change_map[f])
|
||||
else:
|
||||
new_file_list.append(f)
|
||||
if new_file_list != file_list:
|
||||
webnotes.conn.sql("""update `tab%s` set file_list=%s
|
||||
where name=%s""" % (dt[0], "%s", "%s"),
|
||||
("\n".join(new_file_list), name))
|
||||
|
||||
except Exception, e:
|
||||
if e[0]!=1146:
|
||||
print webnotes.getTraceback()
|
||||
raise e
|
||||
|
||||
70
patches/january_2013/stock_reconciliation_patch.py
Normal file
70
patches/january_2013/stock_reconciliation_patch.py
Normal file
@@ -0,0 +1,70 @@
|
||||
import webnotes
|
||||
|
||||
def execute():
|
||||
webnotes.reload_doc("stock", "doctype", "stock_ledger_entry")
|
||||
webnotes.reload_doc("stock", "doctype", "stock_reconciliation")
|
||||
|
||||
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"],
|
||||
["Stock Reconciliation", "reconciliation_date", "posting_date"],
|
||||
["Stock Reconciliation", "reconciliation_time", "posting_time"]]
|
||||
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 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()
|
||||
try:
|
||||
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, reco))
|
||||
except Exception:
|
||||
# if not a valid CSV file, do nothing
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user