fix: batch filter not working in stock ledger report

This commit is contained in:
Rohit Waghchaure 2024-02-16 19:38:45 +05:30
parent fa4ea7c96d
commit a995e87567

View File

@ -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()]