fix: stock levels for batch (backport #41494) (#41501)

fix: stock levels for batch (#41494)

(cherry picked from commit 500c546691)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
mergify[bot]
2024-05-16 16:33:02 +05:30
committed by GitHub
parent 7620ae203e
commit 938888cddd
4 changed files with 14 additions and 7 deletions

View File

@@ -47,9 +47,14 @@ frappe.ui.form.on("Batch", {
}, },
make_dashboard: (frm) => { make_dashboard: (frm) => {
if (!frm.is_new()) { if (!frm.is_new()) {
let for_stock_levels = 0;
if (!frm.doc.batch_qty && frm.doc.expiry_date) {
for_stock_levels = 1;
}
frappe.call({ frappe.call({
method: "erpnext.stock.doctype.batch.batch.get_batch_qty", 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) => { callback: (r) => {
if (!r.message) { if (!r.message) {
return; return;

View File

@@ -199,6 +199,7 @@ def get_batch_qty(
posting_date=None, posting_date=None,
posting_time=None, posting_time=None,
ignore_voucher_nos=None, ignore_voucher_nos=None,
for_stock_levels=False,
): ):
"""Returns batch actual qty if warehouse is passed, """Returns batch actual qty if warehouse is passed,
or returns dict of qty by warehouse if warehouse is None or returns dict of qty by warehouse if warehouse is None
@@ -222,6 +223,7 @@ def get_batch_qty(
"posting_time": posting_time, "posting_time": posting_time,
"batch_no": batch_no, "batch_no": batch_no,
"ignore_voucher_nos": ignore_voucher_nos, "ignore_voucher_nos": ignore_voucher_nos,
"for_stock_levels": for_stock_levels,
} }
) )

View File

@@ -3,8 +3,6 @@ frappe.listview_settings["Batch"] = {
get_indicator: (doc) => { get_indicator: (doc) => {
if (doc.disabled) { if (doc.disabled) {
return [__("Disabled"), "gray", "disabled,=,1"]; return [__("Disabled"), "gray", "disabled,=,1"];
} else if (!doc.batch_qty) {
return [__("Empty"), "gray", "batch_qty,=,0|disabled,=,0"];
} else if ( } else if (
doc.expiry_date && doc.expiry_date &&
frappe.datetime.get_diff(doc.expiry_date, frappe.datetime.nowdate()) <= 0 frappe.datetime.get_diff(doc.expiry_date, frappe.datetime.nowdate()) <= 0
@@ -14,6 +12,8 @@ frappe.listview_settings["Batch"] = {
"red", "red",
"expiry_date,not in,|expiry_date,<=,Today|batch_qty,>,0|disabled,=,0", "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 { } else {
return [__("Active"), "green", "batch_qty,>,0|disabled,=,0"]; return [__("Active"), "green", "batch_qty,>,0|disabled,=,0"];
} }

View File

@@ -1865,14 +1865,14 @@ def get_available_batches(kwargs):
batch_ledger.warehouse, batch_ledger.warehouse,
Sum(batch_ledger.qty).as_("qty"), Sum(batch_ledger.qty).as_("qty"),
) )
.where( .where(batch_table.disabled == 0)
(batch_table.disabled == 0)
& ((batch_table.expiry_date >= today()) | (batch_table.expiry_date.isnull()))
)
.where(stock_ledger_entry.is_cancelled == 0) .where(stock_ledger_entry.is_cancelled == 0)
.groupby(batch_ledger.batch_no, batch_ledger.warehouse) .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_date"):
if kwargs.get("posting_time") is None: if kwargs.get("posting_time") is None:
kwargs.posting_time = nowtime() kwargs.posting_time = nowtime()