Skip to content

Commit 493f36b

Browse files
rohitwaghchauremergify[bot]
authored andcommitted
fix: negative batch report showing same batch-warehouse multiple times
(cherry picked from commit 7005729)
1 parent cd605d3 commit 493f36b

1 file changed

Lines changed: 47 additions & 30 deletions

File tree

erpnext/stock/report/negative_batch_report/negative_batch_report.py

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -90,45 +90,62 @@ def get_data(filters) -> list[dict]:
9090
batch_negative_data = []
9191

9292
flt_precision = frappe.db.get_default("float_precision") or 2
93+
distinct_batches = set()
9394
for company in companies:
94-
for batch in batches:
95-
_c, data = stock_ledger_execute(
96-
frappe._dict(
97-
{
98-
"company": company,
99-
"batch_no": batch,
100-
"from_date": add_to_date(today(), years=-12),
101-
"to_date": today(),
102-
"segregate_serial_batch_bundle": 1,
103-
"warehouse": filters.get("warehouse"),
104-
"valuation_field_type": "Currency",
105-
}
106-
)
107-
)
108-
109-
previous_qty = 0
110-
for row in data:
111-
if flt(row.get("qty_after_transaction"), flt_precision) < 0:
112-
batch_negative_data.append(
95+
warehouses = get_warehouses(filters, company)
96+
for warehouse in warehouses:
97+
for batch in batches:
98+
_c, data = stock_ledger_execute(
99+
frappe._dict(
113100
{
114-
"posting_date": row.get("date"),
115-
"batch_no": row.get("batch_no"),
116-
"item_code": row.get("item_code"),
117-
"item_name": row.get("item_name"),
118-
"warehouse": row.get("warehouse"),
119-
"actual_qty": row.get("actual_qty"),
120-
"qty_after_transaction": row.get("qty_after_transaction"),
121-
"previous_qty": previous_qty,
122-
"voucher_type": row.get("voucher_type"),
123-
"voucher_no": row.get("voucher_no"),
101+
"company": company,
102+
"batch_no": batch,
103+
"from_date": add_to_date(today(), years=-12),
104+
"to_date": today(),
105+
"segregate_serial_batch_bundle": 1,
106+
"warehouse": warehouse,
107+
"valuation_field_type": "Currency",
124108
}
125109
)
110+
)
126111

127-
previous_qty = row.get("qty_after_transaction")
112+
previous_qty = 0
113+
for row in data:
114+
key = (row.get("warehouse"), batch)
115+
if key in distinct_batches:
116+
continue
117+
118+
if flt(row.get("qty_after_transaction"), flt_precision) < 0:
119+
batch_negative_data.append(
120+
{
121+
"posting_date": row.get("date"),
122+
"batch_no": row.get("batch_no"),
123+
"item_code": row.get("item_code"),
124+
"item_name": row.get("item_name"),
125+
"warehouse": row.get("warehouse"),
126+
"actual_qty": row.get("actual_qty"),
127+
"qty_after_transaction": row.get("qty_after_transaction"),
128+
"previous_qty": previous_qty,
129+
"voucher_type": row.get("voucher_type"),
130+
"voucher_no": row.get("voucher_no"),
131+
}
132+
)
133+
134+
distinct_batches.add(key)
135+
136+
previous_qty = row.get("qty_after_transaction")
128137

129138
return batch_negative_data
130139

131140

141+
def get_warehouses(filters, company):
142+
warehouse_filters = {"company": company, "disabled": 0}
143+
if filters.get("warehouse"):
144+
warehouse_filters["name"] = filters["warehouse"]
145+
146+
return frappe.get_all("Warehouse", pluck="name", filters=warehouse_filters)
147+
148+
132149
def get_batches(filters):
133150
batch_filters = {}
134151
if filters.get("item_code"):

0 commit comments

Comments
 (0)