mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-04 20:59:11 +00:00
refactor: use existing functionality
This commit is contained in:
@@ -360,28 +360,8 @@ class StockBalanceReport:
|
|||||||
def apply_warehouse_filters(self, query, sle) -> str:
|
def apply_warehouse_filters(self, query, sle) -> str:
|
||||||
warehouse_table = frappe.qb.DocType("Warehouse")
|
warehouse_table = frappe.qb.DocType("Warehouse")
|
||||||
|
|
||||||
if warehouses := self.filters.get("warehouse"):
|
if self.filters.get("warehouse"):
|
||||||
warehouse_range = frappe.get_all(
|
apply_warehouse_filter(query, sle, self.filters)
|
||||||
"Warehouse",
|
|
||||||
filters={
|
|
||||||
"name": ("in", warehouses),
|
|
||||||
},
|
|
||||||
fields=["lft", "rgt"],
|
|
||||||
as_list=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
child_query = frappe.qb.from_(warehouse_table).select(warehouse_table.name)
|
|
||||||
|
|
||||||
range_conditions = [
|
|
||||||
(warehouse_table.lft >= lft) & (warehouse_table.rgt <= rgt) for lft, rgt in warehouse_range
|
|
||||||
]
|
|
||||||
|
|
||||||
combined_condition = range_conditions[0]
|
|
||||||
for condition in range_conditions[1:]:
|
|
||||||
combined_condition = combined_condition | condition
|
|
||||||
|
|
||||||
child_query = child_query.where(combined_condition & (warehouse_table.name == sle.warehouse))
|
|
||||||
query = query.where(ExistsCriterion(child_query))
|
|
||||||
|
|
||||||
elif warehouse_type := self.filters.get("warehouse_type"):
|
elif warehouse_type := self.filters.get("warehouse_type"):
|
||||||
query = (
|
query = (
|
||||||
|
|||||||
Reference in New Issue
Block a user