fixed order by for common queries, should be ordered based on startswith match and then alphabetical order for fuzzy match

This commit is contained in:
Anand Doshi 2012-11-21 18:00:22 +05:30
parent f8c5960cc2
commit b45cbda7fa
3 changed files with 74 additions and 57 deletions

View File

@ -22,7 +22,11 @@ erpnext.utils.profile_query = function() {
from `tabProfile` where ifnull(enabled, 0)=1 and docstatus < 2 and \
name not in ('Administrator', 'Guest') and (%(key)s like \"%s\" or \
concat_ws(' ', first_name, middle_name, last_name) like \"%%%s\") \
order by name asc limit 50";
order by \
case when name like \"%s%%\" then 0 else 1 end, \
case when concat_ws(' ', first_name, middle_name, last_name) like \"%s%%\" \
then 0 else 1 end, \
name asc limit 50";
};
// searches for active employees
@ -30,7 +34,10 @@ erpnext.utils.employee_query = function() {
return "select name, employee_name from `tabEmployee` \
where status = 'Active' and docstatus < 2 and \
(%(key)s like \"%s\" or employee_name like \"%%%s\") \
order by name asc limit 50";
order by \
case when name like \"%s%%\" then 0 else 1 end, \
case when employee_name like \"%s%%\" then 0 else 1 end, \
name limit 50";
};
// searches for leads which are not converted
@ -38,5 +45,9 @@ erpnext.utils.lead_query = function() {
return "select name, lead_name, company_name from `tabLead` \
where docstatus < 2 and ifnull(status, '') != 'Converted' and \
(%(key)s like \"%s\" or lead_name like \"%%%s\" or company_name like \"%%%s\") \
order by lead_name asc limit 50";
order by \
case when name like \"%s%%\" then 0 else 1 end, \
case when lead_name like \"%s%%\" then 0 else 1 end, \
case when company_name like \"%s%%\" then 0 else 1 end, \
lead_name asc limit 50";
};

View File

@ -3,9 +3,9 @@
# These values are common in all dictionaries
{
u'creation': '2012-08-08 10:41:31',
u'creation': '2012-11-19 12:06:56',
u'docstatus': 0,
u'modified': '2012-11-16 12:26:14',
u'modified': '2012-11-21 17:12:54',
u'modified_by': u'Administrator',
u'owner': u'Administrator'
},
@ -40,12 +40,14 @@
# These values are common for all DocPerm
{
'amend': 0,
u'doctype': u'DocPerm',
u'name': u'__common__',
'parent': u'Lead',
'parentfield': u'permissions',
'parenttype': u'DocType',
'read': 1
'read': 1,
'submit': 0
},
# DocType, Lead
@ -146,7 +148,7 @@
{
'colour': u'White:FFF',
'depends_on': u"eval:doc.source == 'Existing Customer'",
'description': u'Source of th',
'description': u'Source of the Lead',
u'doctype': u'DocField',
'fieldname': u'customer',
'fieldtype': u'Link',
@ -626,77 +628,81 @@
# DocPerm
{
'cancel': 0,
'create': 0,
u'doctype': u'DocPerm',
'permlevel': 1,
'role': u'All',
'write': 0
},
# DocPerm
{
'cancel': 0,
'create': 1,
u'doctype': u'DocPerm',
'permlevel': 0,
'role': u'Guest',
'role': u'Sales User',
'write': 1
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
u'doctype': u'DocPerm',
'permlevel': 1,
'role': u'Sales User',
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
u'doctype': u'DocPerm',
'permlevel': 1,
'role': u'Sales Manager',
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 0,
'cancel': 1,
'create': 1,
u'doctype': u'DocPerm',
'permlevel': 0,
'role': u'Sales Manager',
'submit': 0,
'write': 1
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 1,
u'doctype': u'DocPerm',
'permlevel': 0,
'role': u'Sales User',
'submit': 0,
'write': 1
},
# DocPerm
{
u'doctype': u'DocPerm',
'permlevel': 1,
'role': u'All'
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 1,
u'doctype': u'DocPerm',
'permlevel': 0,
'role': u'System Manager',
'submit': 0,
'write': 1
},
# DocPerm
{
'cancel': 0,
'create': 0,
u'doctype': u'DocPerm',
'permlevel': 1,
'role': u'Sales Manager',
'write': 0
},
# DocPerm
{
'cancel': 0,
'create': 0,
u'doctype': u'DocPerm',
'permlevel': 1,
'role': u'Sales User',
'write': 0
},
# DocPerm
{
'cancel': 0,
'create': 1,
u'doctype': u'DocPerm',
'permlevel': 0,
'role': u'System Manager',
'write': 1
},
# DocPerm
{
'cancel': 0,
'create': 1,
u'doctype': u'DocPerm',
'permlevel': 0,
'role': u'Guest',
'write': 1
}
]

View File

@ -15,8 +15,8 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
cur_frm.cscript.onload = function(doc, cdt, cdn) {
if(doc.customer) cur_frm.add_fetch('customer', 'customer_name', 'customer_name');
if(doc.supplier) cur_frm.add_fetch('supplier', 'supplier_name', 'supplier_name');
cur_frm.add_fetch('customer', 'customer_name', 'customer_name');
cur_frm.add_fetch('supplier', 'supplier_name', 'supplier_name');
var route = wn.get_route();
if(route[1]=='Supplier') {