[fix] [patch] [minor] sle for deleted stock entry detail
This commit is contained in:
parent
eb9194f66d
commit
fe14f69e71
@ -1,23 +1,119 @@
|
|||||||
import webnotes
|
import webnotes
|
||||||
|
|
||||||
|
cancelled = []
|
||||||
|
uncancelled = []
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
from stock.stock_ledger import update_entries_after
|
from stock.stock_ledger import update_entries_after
|
||||||
|
|
||||||
stock_entries = webnotes.conn.sql("""select name from `tabStock Entry`
|
stock_entries = webnotes.conn.sql("""select * from `tabStock Entry`
|
||||||
where docstatus < 2 and modified >= '2013-08-15'
|
where docstatus >= 1 and date(modified) >= "2013-08-16" and date(modified) <= "2013-08-21"
|
||||||
and ifnull(production_order, '') != '' and ifnull(bom_no, '') != ''""")
|
and ifnull(production_order, '') != '' and ifnull(bom_no, '') != ''
|
||||||
|
order by modified desc, name desc""", as_dict=True)
|
||||||
|
|
||||||
for entry in stock_entries:
|
for entry in stock_entries:
|
||||||
webnotes.conn.sql("""update `tabStock Ledger Entry` set is_cancelled = 'Yes'
|
if not webnotes.conn.sql("""select name from `tabStock Entry Detail`
|
||||||
where voucher_type = 'Stock Entry' and voucher_no = %s""", entry[0])
|
where parent=%s""", entry.name):
|
||||||
|
res = webnotes.conn.sql("""select * from `tabStock Ledger Entry`
|
||||||
|
where voucher_type='Stock Entry' and voucher_no=%s
|
||||||
|
and is_cancelled='No'""", entry.name, as_dict=True)
|
||||||
|
if res:
|
||||||
|
print entry
|
||||||
|
make_stock_entry_detail(entry, res)
|
||||||
|
|
||||||
|
if cancelled or uncancelled:
|
||||||
|
send_email()
|
||||||
|
|
||||||
item_warehouse = webnotes.conn.sql("""select distinct item_code, warehouse
|
def make_stock_entry_detail(entry, res):
|
||||||
from `tabStock Ledger Entry`
|
global cancelled, uncancelled
|
||||||
where voucher_type = 'Stock Entry' and voucher_no = %s""", entry[0], as_dict=1)
|
|
||||||
|
fg_item = webnotes.conn.get_value("Production Order", entry.production_order,
|
||||||
for d in item_warehouse:
|
"production_item")
|
||||||
update_entries_after({
|
voucher_detail_entries_map = {}
|
||||||
"item_code": d.item_code,
|
for sle in res:
|
||||||
"warehouse": d.warehouse,
|
voucher_detail_entries_map.setdefault(sle.voucher_detail_no, []).append(sle)
|
||||||
"posting_date": "2013-08-15",
|
|
||||||
"posting_date": "01:00"
|
for i, voucher_detail_no in enumerate(sorted(voucher_detail_entries_map.keys())):
|
||||||
})
|
sl_entries = voucher_detail_entries_map[voucher_detail_no]
|
||||||
|
# create stock entry details back from stock ledger entries
|
||||||
|
stock_entry_detail = webnotes.doc({
|
||||||
|
"doctype": "Stock Entry Detail",
|
||||||
|
"parentfield": "mtn_details",
|
||||||
|
"parenttype": "Stock Entry",
|
||||||
|
"parent": entry.name,
|
||||||
|
"__islocal": 1,
|
||||||
|
"idx": i+1,
|
||||||
|
"docstatus": 1,
|
||||||
|
"owner": entry.owner,
|
||||||
|
"name": voucher_detail_no,
|
||||||
|
"transfer_qty": abs(sl_entries[0].actual_qty),
|
||||||
|
"qty": abs(sl_entries[0].actual_qty),
|
||||||
|
"stock_uom": sl_entries[0].stock_uom,
|
||||||
|
"uom": sl_entries[0].stock_uom,
|
||||||
|
"conversion_factor": 1,
|
||||||
|
"item_code": sl_entries[0].item_code,
|
||||||
|
"description": webnotes.conn.get_value("Item", sl_entries[0].item_code,
|
||||||
|
"description"),
|
||||||
|
"incoming_rate": sl_entries[0].incoming_rate,
|
||||||
|
"batch_no": sl_entries[0].batch_no,
|
||||||
|
"serial_no": sl_entries[0].serial_no
|
||||||
|
})
|
||||||
|
|
||||||
|
if sl_entries[0].item_code == fg_item:
|
||||||
|
stock_entry_detail.bom_no = entry.bom_no
|
||||||
|
|
||||||
|
for sle in sl_entries:
|
||||||
|
if sle.actual_qty < 0:
|
||||||
|
stock_entry_detail.s_warehouse = sle.warehouse
|
||||||
|
else:
|
||||||
|
stock_entry_detail.t_warehouse = sle.warehouse
|
||||||
|
|
||||||
|
stock_entry_detail.save()
|
||||||
|
|
||||||
|
if entry.docstatus == 2:
|
||||||
|
webnotes.conn.set_value("Stock Entry", entry.name, "docstatus", 1)
|
||||||
|
|
||||||
|
# call for cancelled ones
|
||||||
|
se = webnotes.bean("Stock Entry", entry.name)
|
||||||
|
controller = se.make_controller()
|
||||||
|
controller.update_production_order(1)
|
||||||
|
|
||||||
|
res = webnotes.conn.sql("""select name from `tabStock Entry`
|
||||||
|
where amended_from=%s""", entry.name)
|
||||||
|
if res:
|
||||||
|
cancelled.append(res[0][0])
|
||||||
|
if res[0][0] in uncancelled:
|
||||||
|
uncancelled.remove(res[0][0])
|
||||||
|
|
||||||
|
webnotes.bean("Stock Entry", res[0][0]).cancel()
|
||||||
|
|
||||||
|
uncancelled.append(se.doc.name)
|
||||||
|
|
||||||
|
def send_email():
|
||||||
|
from webnotes.utils.email_lib import sendmail_to_system_managers
|
||||||
|
global cancelled, uncancelled
|
||||||
|
uncancelled = "we have undone the cancellation of the following Stock Entries through a patch:\n" + \
|
||||||
|
"\n".join(uncancelled) if uncancelled else ""
|
||||||
|
cancelled = "and cancelled the following Stock Entries:\n" + "\n".join(cancelled) \
|
||||||
|
if cancelled else ""
|
||||||
|
|
||||||
|
subject = "[ERPNext] [Important] Cancellation undone for some Stock Entries"
|
||||||
|
content = """Dear user,
|
||||||
|
|
||||||
|
An error got introduced into the code that cleared the item table in Stock Entry associated to a Production Order.
|
||||||
|
|
||||||
|
Hence,
|
||||||
|
%s
|
||||||
|
|
||||||
|
%s
|
||||||
|
|
||||||
|
You will have to edit them again.
|
||||||
|
|
||||||
|
Sorry for the inconvenience this has caused.
|
||||||
|
|
||||||
|
Regards,
|
||||||
|
Team ERPNext.""" % (uncancelled, cancelled)
|
||||||
|
|
||||||
|
print subject, content
|
||||||
|
|
||||||
|
# sendmail_to_system_managers(subject, content)
|
Loading…
x
Reference in New Issue
Block a user