diff --git a/erpnext/stock/doctype/batch/batch.js b/erpnext/stock/doctype/batch/batch.js index 3719c96c6e7..4ed428421ca 100644 --- a/erpnext/stock/doctype/batch/batch.js +++ b/erpnext/stock/doctype/batch/batch.js @@ -47,9 +47,14 @@ frappe.ui.form.on("Batch", { }, make_dashboard: (frm) => { if (!frm.is_new()) { + let for_stock_levels = 0; + if (!frm.doc.batch_qty && frm.doc.expiry_date) { + for_stock_levels = 1; + } + frappe.call({ method: "erpnext.stock.doctype.batch.batch.get_batch_qty", - args: { batch_no: frm.doc.name, item_code: frm.doc.item }, + args: { batch_no: frm.doc.name, item_code: frm.doc.item, for_stock_levels: for_stock_levels }, callback: (r) => { if (!r.message) { return; diff --git a/erpnext/stock/doctype/batch/batch.py b/erpnext/stock/doctype/batch/batch.py index 8726642cb43..77b87aa995c 100644 --- a/erpnext/stock/doctype/batch/batch.py +++ b/erpnext/stock/doctype/batch/batch.py @@ -199,6 +199,7 @@ def get_batch_qty( posting_date=None, posting_time=None, ignore_voucher_nos=None, + for_stock_levels=False, ): """Returns batch actual qty if warehouse is passed, or returns dict of qty by warehouse if warehouse is None @@ -222,6 +223,7 @@ def get_batch_qty( "posting_time": posting_time, "batch_no": batch_no, "ignore_voucher_nos": ignore_voucher_nos, + "for_stock_levels": for_stock_levels, } ) diff --git a/erpnext/stock/doctype/batch/batch_list.js b/erpnext/stock/doctype/batch/batch_list.js index 2060d6e8763..644ef131399 100644 --- a/erpnext/stock/doctype/batch/batch_list.js +++ b/erpnext/stock/doctype/batch/batch_list.js @@ -3,8 +3,6 @@ frappe.listview_settings["Batch"] = { get_indicator: (doc) => { if (doc.disabled) { return [__("Disabled"), "gray", "disabled,=,1"]; - } else if (!doc.batch_qty) { - return [__("Empty"), "gray", "batch_qty,=,0|disabled,=,0"]; } else if ( doc.expiry_date && frappe.datetime.get_diff(doc.expiry_date, frappe.datetime.nowdate()) <= 0 @@ -14,6 +12,8 @@ frappe.listview_settings["Batch"] = { "red", "expiry_date,not in,|expiry_date,<=,Today|batch_qty,>,0|disabled,=,0", ]; + } else if (!doc.batch_qty) { + return [__("Empty"), "gray", "batch_qty,=,0|disabled,=,0"]; } else { return [__("Active"), "green", "batch_qty,>,0|disabled,=,0"]; } diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py index 4c9fc881986..5e16115db01 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py +++ b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py @@ -1865,14 +1865,14 @@ def get_available_batches(kwargs): batch_ledger.warehouse, Sum(batch_ledger.qty).as_("qty"), ) - .where( - (batch_table.disabled == 0) - & ((batch_table.expiry_date >= today()) | (batch_table.expiry_date.isnull())) - ) + .where(batch_table.disabled == 0) .where(stock_ledger_entry.is_cancelled == 0) .groupby(batch_ledger.batch_no, batch_ledger.warehouse) ) + if not kwargs.get("for_stock_levels"): + query = query.where((batch_table.expiry_date >= today()) | (batch_table.expiry_date.isnull())) + if kwargs.get("posting_date"): if kwargs.get("posting_time") is None: kwargs.posting_time = nowtime()