From 9ab15a590cdcbbd361768240f43eb64fc246eed2 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 1 Aug 2024 22:44:50 +0530 Subject: [PATCH] fix: all warehouse filter for the stock report (cherry picked from commit a4311e345d782361a58904b874c1d66fd2516761) --- .../stock/report/stock_ageing/stock_ageing.py | 5 +++- ...rehouse_wise_item_balance_age_and_value.py | 29 +++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/erpnext/stock/report/stock_ageing/stock_ageing.py b/erpnext/stock/report/stock_ageing/stock_ageing.py index 8738b65f50d4..09af3f224a32 100644 --- a/erpnext/stock/report/stock_ageing/stock_ageing.py +++ b/erpnext/stock/report/stock_ageing/stock_ageing.py @@ -465,10 +465,13 @@ def __get_bundle_wise_serial_nos(self) -> dict: ) ) - for field in ["item_code", "warehouse"]: + for field in ["item_code"]: if self.filters.get(field): query = query.where(bundle[field] == self.filters.get(field)) + if self.filters.get("warehouse"): + query = self.__get_warehouse_conditions(bundle, query) + bundle_wise_serial_nos = frappe._dict({}) for bundle_name, serial_no in query.run(): bundle_wise_serial_nos.setdefault(bundle_name, []).append(serial_no) diff --git a/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.py b/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.py index f5a059a7f61a..0df8b6ddb48b 100644 --- a/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.py +++ b/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.py @@ -114,18 +114,23 @@ def validate_filters(filters): def get_warehouse_list(filters): - from frappe.core.doctype.user_permission.user_permission import get_permitted_documents - - wh = frappe.qb.DocType("Warehouse") - query = frappe.qb.from_(wh).select(wh.name).where(wh.is_group == 0) - - user_permitted_warehouse = get_permitted_documents("Warehouse") - if user_permitted_warehouse: - query = query.where(wh.name.isin(set(user_permitted_warehouse))) - elif filters.get("warehouse"): - query = query.where(wh.name == filters.get("warehouse")) - - return query.run(as_dict=True) + if not filters.get("warehouse"): + return frappe.get_all( + "Warehouse", + filters={"company": filters.get("company"), "is_group": 0}, + fields=["name"], + order_by="name", + ) + + warehouse = frappe.qb.DocType("Warehouse") + lft, rgt = frappe.db.get_value("Warehouse", filters.get("warehouse"), ["lft", "rgt"]) + + return ( + frappe.qb.from_(warehouse) + .select("name") + .where((warehouse.lft >= lft) & (warehouse.rgt <= rgt)) + .run(as_dict=True) + ) def add_warehouse_column(columns, warehouse_list):