fix: batch filter not working in stock ledger report
(cherry picked from commit a995e87567
)
Co-authored-by: Rohit Waghchaure <rohitw1991@gmail.com>
This commit is contained in:
parent
b91f65d4cf
commit
15135952fc
@ -320,15 +320,45 @@ def get_stock_ledger_entries(filters, items):
|
||||
if items:
|
||||
query = query.where(sle.item_code.isin(items))
|
||||
|
||||
for field in ["voucher_no", "batch_no", "project", "company"]:
|
||||
for field in ["voucher_no", "project", "company"]:
|
||||
if filters.get(field) and field not in inventory_dimension_fields:
|
||||
query = query.where(sle[field] == filters.get(field))
|
||||
|
||||
if filters.get("batch_no"):
|
||||
bundles = get_serial_and_batch_bundles(filters)
|
||||
|
||||
if bundles:
|
||||
query = query.where(
|
||||
(sle.serial_and_batch_bundle.isin(bundles)) | (sle.batch_no == filters.batch_no)
|
||||
)
|
||||
else:
|
||||
query = query.where(sle.batch_no == filters.batch_no)
|
||||
|
||||
query = apply_warehouse_filter(query, sle, filters)
|
||||
|
||||
return query.run(as_dict=True)
|
||||
|
||||
|
||||
def get_serial_and_batch_bundles(filters):
|
||||
SBB = frappe.qb.DocType("Serial and Batch Bundle")
|
||||
SBE = frappe.qb.DocType("Serial and Batch Entry")
|
||||
|
||||
query = (
|
||||
frappe.qb.from_(SBE)
|
||||
.inner_join(SBB)
|
||||
.on(SBE.parent == SBB.name)
|
||||
.select(SBE.parent)
|
||||
.where(
|
||||
(SBB.docstatus == 1)
|
||||
& (SBB.has_batch_no == 1)
|
||||
& (SBB.voucher_no.notnull())
|
||||
& (SBE.batch_no == filters.batch_no)
|
||||
)
|
||||
)
|
||||
|
||||
return query.run(pluck=SBE.parent)
|
||||
|
||||
|
||||
def get_inventory_dimension_fields():
|
||||
return [dimension.fieldname for dimension in get_inventory_dimensions()]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user