Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: all warehouse filter for the stock report (backport #42584) #42604

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading