mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-23 21:22:42 +01:00
fix: stock entry not fetching expired batches (#44863)
(cherry picked from commit c9b143b509)
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -156,7 +156,7 @@ class StockController(AccountsController):
|
|||||||
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
||||||
|
|
||||||
is_material_issue = False
|
is_material_issue = False
|
||||||
if self.doctype == "Stock Entry" and self.purpose == "Material Issue":
|
if self.doctype == "Stock Entry" and self.purpose in ["Material Issue", "Material Transfer"]:
|
||||||
is_material_issue = True
|
is_material_issue = True
|
||||||
|
|
||||||
for d in self.get("items"):
|
for d in self.get("items"):
|
||||||
|
|||||||
@@ -371,6 +371,7 @@ frappe.ui.form.on("Stock Entry", {
|
|||||||
function () {
|
function () {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "erpnext.stock.doctype.stock_entry.stock_entry.get_expired_batch_items",
|
method: "erpnext.stock.doctype.stock_entry.stock_entry.get_expired_batch_items",
|
||||||
|
freeze: true,
|
||||||
callback: function (r) {
|
callback: function (r) {
|
||||||
if (!r.exc && r.message) {
|
if (!r.exc && r.message) {
|
||||||
frm.set_value("items", []);
|
frm.set_value("items", []);
|
||||||
|
|||||||
@@ -2975,17 +2975,45 @@ def get_uom_details(item_code, uom, qty):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_expired_batch_items():
|
def get_expired_batch_items():
|
||||||
return frappe.db.sql(
|
from erpnext.stock.doctype.serial_and_batch_bundle.serial_and_batch_bundle import get_auto_batch_nos
|
||||||
"""select b.item, sum(sle.actual_qty) as qty, sle.batch_no, sle.warehouse, sle.stock_uom\
|
|
||||||
from `tabBatch` b, `tabStock Ledger Entry` sle
|
expired_batches = get_expired_batches()
|
||||||
where b.expiry_date <= %s
|
if not expired_batches:
|
||||||
and b.expiry_date is not NULL
|
return []
|
||||||
and b.batch_id = sle.batch_no and sle.is_cancelled = 0
|
|
||||||
group by sle.warehouse, sle.item_code, sle.batch_no""",
|
expired_batches_stock = get_auto_batch_nos(
|
||||||
(nowdate()),
|
frappe._dict(
|
||||||
as_dict=1,
|
{
|
||||||
|
"batch_no": list(expired_batches.keys()),
|
||||||
|
"for_stock_levels": True,
|
||||||
|
}
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for row in expired_batches_stock:
|
||||||
|
row.update(expired_batches.get(row.batch_no))
|
||||||
|
|
||||||
|
return expired_batches_stock
|
||||||
|
|
||||||
|
|
||||||
|
def get_expired_batches():
|
||||||
|
batch = frappe.qb.DocType("Batch")
|
||||||
|
|
||||||
|
data = (
|
||||||
|
frappe.qb.from_(batch)
|
||||||
|
.select(batch.item, batch.name.as_("batch_no"), batch.stock_uom)
|
||||||
|
.where((batch.expiry_date <= nowdate()) & (batch.expiry_date.isnotnull()))
|
||||||
|
).run(as_dict=True)
|
||||||
|
|
||||||
|
if not data:
|
||||||
|
return []
|
||||||
|
|
||||||
|
expired_batches = frappe._dict()
|
||||||
|
for row in data:
|
||||||
|
expired_batches[row.batch_no] = row
|
||||||
|
|
||||||
|
return expired_batches
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_warehouse_details(args):
|
def get_warehouse_details(args):
|
||||||
|
|||||||
Reference in New Issue
Block a user