From 31fe6a378c3ab16067e5df6407f0fa7305fb09b1 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Sat, 18 Apr 2026 17:33:01 +0530 Subject: [PATCH] fix: exclude group warehouse in the report --- .../negative_batch_report.js | 1 + .../negative_batch_report.py | 93 +++++++++---------- 2 files changed, 44 insertions(+), 50 deletions(-) diff --git a/erpnext/stock/report/negative_batch_report/negative_batch_report.js b/erpnext/stock/report/negative_batch_report/negative_batch_report.js index 3bfe8fe9c85..1561cf2cc58 100644 --- a/erpnext/stock/report/negative_batch_report/negative_batch_report.js +++ b/erpnext/stock/report/negative_batch_report/negative_batch_report.js @@ -32,6 +32,7 @@ frappe.query_reports["Negative Batch Report"] = { return { filters: { is_group: 0, + disabled: 0, company: frappe.query_report.get_filter_value("company"), }, }; diff --git a/erpnext/stock/report/negative_batch_report/negative_batch_report.py b/erpnext/stock/report/negative_batch_report/negative_batch_report.py index e6b2c1a747d..f29fe3b8d63 100644 --- a/erpnext/stock/report/negative_batch_report/negative_batch_report.py +++ b/erpnext/stock/report/negative_batch_report/negative_batch_report.py @@ -86,64 +86,65 @@ def get_columns() -> list[dict]: def get_data(filters) -> list[dict]: batches = get_batches(filters) - companies = get_companies(filters) batch_negative_data = [] flt_precision = frappe.db.get_default("float_precision") or 2 distinct_batches = set() - for company in companies: - warehouses = get_warehouses(filters, company) - for warehouse in warehouses: - for batch in batches: - _c, data = stock_ledger_execute( - frappe._dict( + warehouses = get_warehouses(filters) + for _warehouse in warehouses: + for batch in batches: + _c, data = stock_ledger_execute( + frappe._dict( + { + "batch_no": batch, + "from_date": add_to_date(today(), years=-12), + "to_date": today(), + "warehouse": _warehouse.name, + "company": _warehouse.company, + "valuation_field_type": "Currency", + "segregate_serial_batch_bundle": 1, + } + ) + ) + + previous_qty = 0 + 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: + batch_negative_data.append( { - "company": company, - "batch_no": batch, - "from_date": add_to_date(today(), years=-12), - "to_date": today(), - "segregate_serial_batch_bundle": 1, - "warehouse": warehouse, - "valuation_field_type": "Currency", + "posting_date": row.get("date"), + "batch_no": row.get("batch_no"), + "item_code": row.get("item_code"), + "item_name": row.get("item_name"), + "warehouse": row.get("warehouse"), + "actual_qty": row.get("actual_qty"), + "qty_after_transaction": row.get("qty_after_transaction"), + "previous_qty": previous_qty, + "voucher_type": row.get("voucher_type"), + "voucher_no": row.get("voucher_no"), } ) - ) - previous_qty = 0 - for row in data: - key = (row.get("warehouse"), batch) - if key in distinct_batches: - continue + distinct_batches.add(key) - if flt(row.get("qty_after_transaction"), flt_precision) < 0: - batch_negative_data.append( - { - "posting_date": row.get("date"), - "batch_no": row.get("batch_no"), - "item_code": row.get("item_code"), - "item_name": row.get("item_name"), - "warehouse": row.get("warehouse"), - "actual_qty": row.get("actual_qty"), - "qty_after_transaction": row.get("qty_after_transaction"), - "previous_qty": previous_qty, - "voucher_type": row.get("voucher_type"), - "voucher_no": row.get("voucher_no"), - } - ) - - distinct_batches.add(key) - - previous_qty = row.get("qty_after_transaction") + previous_qty = row.get("qty_after_transaction") return batch_negative_data -def get_warehouses(filters, company): - warehouse_filters = {"company": company, "disabled": 0} +def get_warehouses(filters): + warehouse_filters = {"disabled": 0, "is_group": 0} + if filters.get("company"): + warehouse_filters["company"] = filters["company"] + if filters.get("warehouse"): warehouse_filters["name"] = filters["warehouse"] - return frappe.get_all("Warehouse", pluck="name", filters=warehouse_filters) + return frappe.get_all("Warehouse", fields=["name", "company"], filters=warehouse_filters) def get_batches(filters): @@ -152,11 +153,3 @@ def get_batches(filters): batch_filters["item"] = filters["item_code"] return frappe.get_all("Batch", pluck="name", filters=batch_filters) - - -def get_companies(filters): - company_filters = {} - if filters.get("company"): - company_filters["name"] = filters["company"] - - return frappe.get_all("Company", pluck="name", filters=company_filters)