mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 03:09:09 +00:00
merge
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
from __future__ import unicode_literals
|
||||
def execute():
|
||||
import webnotes
|
||||
from webnotes.model.code import get_obj
|
||||
|
||||
bins = webnotes.conn.sql("select distinct t2.name from `tabStock Ledger Entry` t1, tabBin t2 where t1.posting_time > '00:00:00' and t1.posting_time < '00:01:00' and t1.item_code = t2.item_code and t1.warehouse = t2.warehouse")
|
||||
res = webnotes.conn.sql("""select distinct item_code, warehouse from `tabStock Ledger Entry`
|
||||
where posting_time > '00:00:00' and posting_time < '00:01:00'""", as_dict=1)
|
||||
webnotes.conn.sql("update `tabStock Ledger Entry` set posting_time = '00:00:00' where posting_time > '00:00:00' and posting_time < '00:01:00'")
|
||||
|
||||
for d in bins:
|
||||
get_obj('Bin', d[0]).update_entries_after(posting_date = '2000-01-01', posting_time = '12:01')
|
||||
from stock.stock_ledger import update_entries_after
|
||||
for d in res:
|
||||
update_entries_after({
|
||||
"item_code": d.item_code,
|
||||
"warehouse": d.warehouse,
|
||||
})
|
||||
|
||||
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
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from stock.stock_ledger import update_entries_after
|
||||
|
||||
def execute():
|
||||
# add index
|
||||
@@ -80,8 +81,13 @@ def cleanup_wrong_sle():
|
||||
for d in sle:
|
||||
webnotes.conn.sql("update `tabStock Ledger Entry` set is_cancelled = 'Yes' where name = %s", d[3])
|
||||
create_comment(d[3])
|
||||
repost_bin(d[0], d[1])
|
||||
|
||||
update_entries_after({
|
||||
"item_code": d[0],
|
||||
"warehouse": d[1],
|
||||
"posting_date": "2012-07-01",
|
||||
"posting_time": "12:05"
|
||||
})
|
||||
|
||||
def create_comment(dn):
|
||||
from webnotes.model.doc import Document
|
||||
cmt = Document('Comment')
|
||||
@@ -91,11 +97,4 @@ def create_comment(dn):
|
||||
cmt.comment_doctype = 'Stock Ledger Entry'
|
||||
cmt.comment_docname = dn
|
||||
cmt.save(1)
|
||||
|
||||
|
||||
def repost_bin(item, wh):
|
||||
from webnotes.model.code import get_obj
|
||||
bin = webnotes.conn.sql("select name from `tabBin` \
|
||||
where item_code = %s and warehouse = %s", (item, wh))
|
||||
|
||||
get_obj('Bin', bin[0][0]).update_entries_after(posting_date = '2012-07-01', posting_time = '12:05')
|
||||
|
||||
@@ -582,6 +582,10 @@ patch_list = [
|
||||
'patch_module': 'patches.january_2013',
|
||||
'patch_file': 'holiday_list_patch',
|
||||
},
|
||||
{
|
||||
'patch_module': 'patches.january_2013',
|
||||
'patch_file': 'stock_reconciliation_patch',
|
||||
},
|
||||
{
|
||||
'patch_module': 'patches.january_2013',
|
||||
'patch_file': 'report_permission',
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
from __future__ import unicode_literals
|
||||
def execute():
|
||||
import webnotes
|
||||
from webnotes.model.code import get_obj
|
||||
bin = webnotes.conn.sql("select name from `tabBin`")
|
||||
from stock.stock_ledger import update_entries_after
|
||||
res = webnotes.conn.sql("select distinct item_code, warehouse from `tabStock Ledger Entry`")
|
||||
i=0
|
||||
for d in bin:
|
||||
for d in res:
|
||||
try:
|
||||
get_obj('Bin', d[0]).update_entries_after('2000-01-01', '12:05')
|
||||
update_entries_after({ "item_code": d[0], "warehouse": d[1] })
|
||||
except:
|
||||
pass
|
||||
i += 1
|
||||
|
||||
Reference in New Issue
Block a user