Skip to content

Commit

Permalink
feat: In sidebar filter link field show Title of Field if set (frappe…
Browse files Browse the repository at this point in the history
  • Loading branch information
rareMaxim committed May 12, 2024
1 parent 7eeb664 commit 80fd5a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions frappe/desk/listview.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ def get_group_by_count(doctype: str, current_filters: str, field: str) -> list[d

if not frappe.get_meta(doctype).has_field(field) and not is_default_field(field):
raise ValueError("Field does not belong to doctype")

meta_field = frappe.get_meta(doctype).get_field(field) # get field info
if meta_field.fieldtype == "Link": # if field is link
# get list (count, name)
raw_list = frappe.get_list(
doctype,
filters=current_filters,
group_by=f"`tab{doctype}`.{field}",
fields=["count(*) as count", f"`{field}` as name"],
order_by="count desc",
limit=50,
)
# get title field name
title_field = frappe.get_meta(meta_field.options).get_title_field()
# add title to items
for item in raw_list:
item.title = frappe.get_value(meta_field.options, item.name, title_field)
return raw_list

return frappe.get_list(
doctype,
Expand Down
2 changes: 2 additions & 0 deletions frappe/public/js/frappe/list/list_sidebar_group_by.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ frappe.views.ListGroupBy = class ListGroupBy {
label = __("Me");
} else if (fieldtype && fieldtype == "Check") {
label = field.name == "0" ? __("No") : __("Yes");
} else if (fieldtype && fieldtype == "Link") {
label = __(field.title);
} else {
label = __(field.name);
}
Expand Down

0 comments on commit 80fd5a0

Please sign in to comment.