seitime-frappe/frappe/desk/listview.py
shadrak gurupnor 6c6ff2c16d fix: overriding of owner of doc
feat: Fixed the dilemma of owner field in ToDo document
2022-01-04 13:39:16 +05:30

53 lines
1.6 KiB
Python

# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
# License: MIT. See LICENSE
import frappe
@frappe.whitelist()
def get_list_settings(doctype):
try:
return frappe.get_cached_doc("List View Settings", doctype)
except frappe.DoesNotExistError:
frappe.clear_messages()
@frappe.whitelist()
def set_list_settings(doctype, values):
try:
doc = frappe.get_doc("List View Settings", doctype)
except frappe.DoesNotExistError:
doc = frappe.new_doc("List View Settings")
doc.name = doctype
frappe.clear_messages()
doc.update(frappe.parse_json(values))
doc.save()
@frappe.whitelist()
def get_group_by_count(doctype, current_filters, field):
current_filters = frappe.parse_json(current_filters)
subquery_condition = ''
subquery = frappe.get_all(doctype, filters=current_filters, run=False)
if field == 'assigned_to':
subquery_condition = ' and `tabToDo`.reference_name in ({subquery})'.format(subquery = subquery)
return frappe.db.sql("""select `tabToDo`.allocated_to as name, count(*) as count
from
`tabToDo`, `tabUser`
where
`tabToDo`.status!='Cancelled' and
`tabToDo`.allocated_to = `tabUser`.name and
`tabUser`.user_type = 'System User'
{subquery_condition}
group by
`tabToDo`.allocated_to
order by
count desc
limit 50""".format(subquery_condition = subquery_condition), as_dict=True)
else:
return frappe.db.get_list(doctype,
filters=current_filters,
group_by='`tab{0}`.{1}'.format(doctype, field),
fields=['count(*) as count', '`{}` as name'.format(field)],
order_by='count desc',
limit=50,
)