Skip to content

Commit

Permalink
fix: all warehouse filter for the stock report
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Aug 1, 2024
1 parent fb2aa7d commit a4311e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
5 changes: 4 additions & 1 deletion erpnext/stock/report/stock_ageing/stock_ageing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a4311e3

Please sign in to comment.