fix: negative batch report showing same batch-warehouse multiple times

(cherry picked from commit 700572980d)
This commit is contained in:
Rohit Waghchaure
2026-04-17 18:18:02 +05:30
committed by Mergify
parent d9d8fc6912
commit 3229fce9a5

View File

@@ -90,7 +90,10 @@ def get_data(filters) -> list[dict]:
batch_negative_data = [] batch_negative_data = []
flt_precision = frappe.db.get_default("float_precision") or 2 flt_precision = frappe.db.get_default("float_precision") or 2
distinct_batches = set()
for company in companies: for company in companies:
warehouses = get_warehouses(filters, company)
for warehouse in warehouses:
for batch in batches: for batch in batches:
_c, data = stock_ledger_execute( _c, data = stock_ledger_execute(
frappe._dict( frappe._dict(
@@ -100,7 +103,7 @@ def get_data(filters) -> list[dict]:
"from_date": add_to_date(today(), years=-12), "from_date": add_to_date(today(), years=-12),
"to_date": today(), "to_date": today(),
"segregate_serial_batch_bundle": 1, "segregate_serial_batch_bundle": 1,
"warehouse": filters.get("warehouse"), "warehouse": warehouse,
"valuation_field_type": "Currency", "valuation_field_type": "Currency",
} }
) )
@@ -108,6 +111,10 @@ def get_data(filters) -> list[dict]:
previous_qty = 0 previous_qty = 0
for row in data: for row in data:
key = (row.get("warehouse"), batch)
if key in distinct_batches:
continue
if flt(row.get("qty_after_transaction"), flt_precision) < 0: if flt(row.get("qty_after_transaction"), flt_precision) < 0:
batch_negative_data.append( batch_negative_data.append(
{ {
@@ -124,11 +131,21 @@ def get_data(filters) -> list[dict]:
} }
) )
distinct_batches.add(key)
previous_qty = row.get("qty_after_transaction") previous_qty = row.get("qty_after_transaction")
return batch_negative_data return batch_negative_data
def get_warehouses(filters, company):
warehouse_filters = {"company": company, "disabled": 0}
if filters.get("warehouse"):
warehouse_filters["name"] = filters["warehouse"]
return frappe.get_all("Warehouse", pluck="name", filters=warehouse_filters)
def get_batches(filters): def get_batches(filters):
batch_filters = {} batch_filters = {}
if filters.get("item_code"): if filters.get("item_code"):