Merge pull request #39937 from frappe/mergify/bp/version-15/pr-39935

fix: batch filter not working in stock ledger report (backport #39934) (backport #39935)
This commit is contained in:
rohitwaghchaure 2024-02-16 21:48:52 +05:30 committed by GitHub
commit 709faaac69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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