From fed7b3bb696e7147cccbe2f90a6ebdb299e35339 Mon Sep 17 00:00:00 2001 From: Abdeali Chharchhodawala <99460106+Abdeali099@users.noreply.github.com> Date: Tue, 28 Oct 2025 13:03:16 +0530 Subject: [PATCH] feat: utility to generate filtered list URLs and links for doctype (#34503) --- frappe/utils/data.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/frappe/utils/data.py b/frappe/utils/data.py index a4cfb9a999..9bc90895ac 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -2007,6 +2007,41 @@ def get_url_to_report_with_filters(name, filters, report_type=None, doctype=None return get_url(uri=f"/app/query-report/{quoted(name)}?{filters}") +def get_filtered_list_url(doctype: str, docnames: list[str] | None = None) -> str: + """ + Get a filtered list view URL for a doctype with specific document names. + + :param doctype: The doctype name + :param docnames: List of document names to filter + + :return: URL to the filtered list view + """ + list_url = get_url_to_list(doctype) + + if not docnames: + return list_url + + return "".join((list_url, "?", urlencode({"name": json.dumps(["in", docnames])}))) + + +def get_filtered_list_link(doctype: str, docnames: list[str] | None = None, label: str | None = None) -> str: + """ + Get an HTML link to a filtered list view for a doctype with specific document names. + + :param doctype: The doctype name + :param docnames: List of document names to filter + :param label: Optional label for the link. If not provided, uses doctype + + :return: HTML link to the filtered list view + """ + from frappe import _ + + url = get_filtered_list_url(doctype, docnames) + label = label or _(doctype) + + return f"""{label}""" + + def sql_like(value: str, pattern: str) -> bool: if not (isinstance(pattern, str) and isinstance(value, str)): return False