From d9b4c52046c9f0949c59839190cd65329347418d Mon Sep 17 00:00:00 2001 From: Gaurav Naik Date: Mon, 16 Jan 2017 16:01:25 +0530 Subject: [PATCH] [Fix] Project: Enabled autocomplete for project users --- erpnext/projects/doctype/project/project.py | 25 ++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py index 388f43e93d..0922f07d55 100644 --- a/erpnext/projects/doctype/project/project.py +++ b/erpnext/projects/doctype/project/project.py @@ -8,6 +8,8 @@ from frappe.utils import flt, getdate, get_url from frappe import _ from frappe.model.document import Document +from erpnext.controllers.queries import get_filters_cond +from frappe.desk.reportview import get_match_cond class Project(Document): def get_feed(self): @@ -215,12 +217,29 @@ def get_list_context(context=None): } def get_users_for_project(doctype, txt, searchfield, start, page_len, filters): - return frappe.db.sql("""select name, concat_ws(' ', first_name, middle_name, last_name) + conditions = [] + return frappe.db.sql("""select name, concat_ws(' ', first_name, middle_name, last_name) from `tabUser` where enabled=1 - and name not in ("Guest", "Administrator") + and name not in ("Guest", "Administrator") + and ({key} like %(txt)s + or full_name like %(txt)s) + {fcond} {mcond} order by - name asc""") + if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999), + if(locate(%(_txt)s, full_name), locate(%(_txt)s, full_name), 99999), + idx desc, + name, full_name + limit %(start)s, %(page_len)s""".format(**{ + 'key': searchfield, + 'fcond': get_filters_cond(doctype, filters, conditions), + 'mcond': get_match_cond(doctype) + }), { + 'txt': "%%%s%%" % txt, + '_txt': txt.replace("%", ""), + 'start': start, + 'page_len': page_len + }) @frappe.whitelist() def get_cost_center_name(project):