diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 68d6294848..359d8347d2 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -156,6 +156,29 @@ frappe.ui.form.on('Stock Entry', { }) }, __("Get items from")); } + if (frm.doc.docstatus===0 && frm.doc.purpose == "Material Issue") { + frm.add_custom_button(__('Expired Batches'), function() { + frappe.call({ + method: "erpnext.stock.doctype.stock_entry.stock_entry.get_expired_batch_items", + callback: function(r) { + if (!r.exc && r.message) { + frm.set_value("items", []); + r.message.forEach(function(element) { + let d = frm.add_child("items"); + d.item_code = element.item; + d.s_warehouse = element.warehouse; + d.qty = element.qty; + d.uom = element.stock_uom; + d.conversion_factor = 1; + d.batch_no = element.batch_no; + d.transfer_qty = element.qty; + frm.refresh_fields(); + }); + } + } + }); + }, __("Get items from")); + } if (frm.doc.company) { frm.trigger("toggle_display_account_head"); diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 15518ee0a8..412331eb3f 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -1165,6 +1165,15 @@ def get_uom_details(item_code, uom, qty): } return ret +@frappe.whitelist() +def get_expired_batch_items(): + return frappe.db.sql("""select b.item, sum(sle.actual_qty) as qty, sle.batch_no, sle.warehouse, sle.stock_uom\ + from `tabBatch` b, `tabStock Ledger Entry` sle + where b.expiry_date <= %s + and b.expiry_date is not NULL + and b.batch_id = sle.batch_no + group by sle.warehouse, sle.item_code, sle.batch_no""",(nowdate()), as_dict=1) + @frappe.whitelist() def get_warehouse_details(args): if isinstance(args, string_types):