fix: stock levels for batch (#41494)
(cherry picked from commit 500c546691)
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -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"];
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user