Fixes in queries
This commit is contained in:
parent
0c3bb75fd9
commit
48d3b54e02
@ -32,34 +32,46 @@ def employee_query(doctype, txt, searchfield, start, page_len, filters):
|
|||||||
return frappe.db.sql("""select name, employee_name from `tabEmployee`
|
return frappe.db.sql("""select name, employee_name from `tabEmployee`
|
||||||
where status = 'Active'
|
where status = 'Active'
|
||||||
and docstatus < 2
|
and docstatus < 2
|
||||||
and (%(key)s like "%(txt)s"
|
and ({key} like %(txt)s
|
||||||
or employee_name like "%(txt)s")
|
or employee_name like %(txt)s)
|
||||||
%(mcond)s
|
{mcond}
|
||||||
order by
|
order by
|
||||||
if(locate("%(_txt)s", name), locate("%(_txt)s", name), 99999),
|
if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
|
||||||
if(locate("%(_txt)s", employee_name), locate("%(_txt)s", employee_name), 99999),
|
if(locate(%(_txt)s, employee_name), locate(%(_txt)s, employee_name), 99999),
|
||||||
name, employee_name
|
name, employee_name
|
||||||
limit %(start)s, %(page_len)s""" % {'key': searchfield, 'txt': "%%%s%%" % txt,
|
limit %(start)s, %(page_len)s""".format(**{
|
||||||
|
'key': searchfield,
|
||||||
|
'mcond': get_match_cond(doctype)
|
||||||
|
}), {
|
||||||
|
'txt': "%%%s%%" % txt,
|
||||||
'_txt': txt.replace("%", ""),
|
'_txt': txt.replace("%", ""),
|
||||||
'mcond':get_match_cond(doctype), 'start': start, 'page_len': page_len})
|
'start': start,
|
||||||
|
'page_len': page_len
|
||||||
|
})
|
||||||
|
|
||||||
# searches for leads which are not converted
|
# searches for leads which are not converted
|
||||||
def lead_query(doctype, txt, searchfield, start, page_len, filters):
|
def lead_query(doctype, txt, searchfield, start, page_len, filters):
|
||||||
return frappe.db.sql("""select name, lead_name, company_name from `tabLead`
|
return frappe.db.sql("""select name, lead_name, company_name from `tabLead`
|
||||||
where docstatus < 2
|
where docstatus < 2
|
||||||
and ifnull(status, '') != 'Converted'
|
and ifnull(status, '') != 'Converted'
|
||||||
and (%(key)s like "%(txt)s"
|
and ({key} like %(txt)s
|
||||||
or lead_name like "%(txt)s"
|
or lead_name like %(txt)s
|
||||||
or company_name like "%(txt)s")
|
or company_name like %(txt)s)
|
||||||
%(mcond)s
|
{mcond}
|
||||||
order by
|
order by
|
||||||
if(locate("%(_txt)s", name), locate("%(_txt)s", name), 99999),
|
if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
|
||||||
if(locate("%(_txt)s", lead_name), locate("%(_txt)s", lead_name), 99999),
|
if(locate(%(_txt)s, lead_name), locate(%(_txt)s, lead_name), 99999),
|
||||||
if(locate("%(_txt)s", company_name), locate("%(_txt)s", company_name), 99999),
|
if(locate(%(_txt)s, company_name), locate(%(_txt)s, company_name), 99999),
|
||||||
name, lead_name
|
name, lead_name
|
||||||
limit %(start)s, %(page_len)s""" % {'key': searchfield, 'txt': "%%%s%%" % txt,
|
limit %(start)s, %(page_len)s""".format(**{
|
||||||
|
'key': searchfield,
|
||||||
|
'mcond':get_match_cond(doctype)
|
||||||
|
}), {
|
||||||
|
'txt': "%%%s%%" % txt,
|
||||||
'_txt': txt.replace("%", ""),
|
'_txt': txt.replace("%", ""),
|
||||||
'mcond':get_match_cond(doctype), 'start': start, 'page_len': page_len})
|
'start': start,
|
||||||
|
'page_len': page_len
|
||||||
|
})
|
||||||
|
|
||||||
# searches for customer
|
# searches for customer
|
||||||
def customer_query(doctype, txt, searchfield, start, page_len, filters):
|
def customer_query(doctype, txt, searchfield, start, page_len, filters):
|
||||||
@ -72,19 +84,25 @@ def customer_query(doctype, txt, searchfield, start, page_len, filters):
|
|||||||
|
|
||||||
fields = ", ".join(fields)
|
fields = ", ".join(fields)
|
||||||
|
|
||||||
return frappe.db.sql("""select %(field)s from `tabCustomer`
|
return frappe.db.sql("""select {fields} from `tabCustomer`
|
||||||
where docstatus < 2
|
where docstatus < 2
|
||||||
and (%(key)s like "%(txt)s"
|
and ({key} like %(txt)s
|
||||||
or customer_name like "%(txt)s")
|
or customer_name like %(txt)s)
|
||||||
%(mcond)s
|
{mcond}
|
||||||
order by
|
order by
|
||||||
if(locate("%(_txt)s", name), locate("%(_txt)s", name), 99999),
|
if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
|
||||||
if(locate("%(_txt)s", customer_name), locate("%(_txt)s", customer_name), 99999),
|
if(locate(%(_txt)s, customer_name), locate(%(_txt)s, customer_name), 99999),
|
||||||
name, customer_name
|
name, customer_name
|
||||||
limit %(start)s, %(page_len)s""" % {'field': fields,'key': searchfield,
|
limit %(start)s, %(page_len)s""".format(**{
|
||||||
'txt': "%%%s%%" % txt, '_txt': txt.replace("%", ""),
|
"fields": fields,
|
||||||
'mcond':get_match_cond(doctype),
|
"key": searchfield,
|
||||||
'start': start, 'page_len': page_len})
|
"mcond": get_match_cond(doctype)
|
||||||
|
}), {
|
||||||
|
'txt': "%%%s%%" % txt,
|
||||||
|
'_txt': txt.replace("%", ""),
|
||||||
|
'start': start,
|
||||||
|
'page_len': page_len
|
||||||
|
})
|
||||||
|
|
||||||
# searches for supplier
|
# searches for supplier
|
||||||
def supplier_query(doctype, txt, searchfield, start, page_len, filters):
|
def supplier_query(doctype, txt, searchfield, start, page_len, filters):
|
||||||
@ -95,19 +113,25 @@ def supplier_query(doctype, txt, searchfield, start, page_len, filters):
|
|||||||
fields = ["name", "supplier_name", "supplier_type"]
|
fields = ["name", "supplier_name", "supplier_type"]
|
||||||
fields = ", ".join(fields)
|
fields = ", ".join(fields)
|
||||||
|
|
||||||
return frappe.db.sql("""select %(field)s from `tabSupplier`
|
return frappe.db.sql("""select {field} from `tabSupplier`
|
||||||
where docstatus < 2
|
where docstatus < 2
|
||||||
and (%(key)s like "%(txt)s"
|
and ({key} like %(txt)s
|
||||||
or supplier_name like "%(txt)s")
|
or supplier_name like %(txt)s)
|
||||||
%(mcond)s
|
{mcond}
|
||||||
order by
|
order by
|
||||||
if(locate("%(_txt)s", name), locate("%(_txt)s", name), 99999),
|
if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
|
||||||
if(locate("%(_txt)s", supplier_name), locate("%(_txt)s", supplier_name), 99999),
|
if(locate(%(_txt)s, supplier_name), locate(%(_txt)s, supplier_name), 99999),
|
||||||
name, supplier_name
|
name, supplier_name
|
||||||
limit %(start)s, %(page_len)s """ % {'field': fields,'key': searchfield,
|
limit %(start)s, %(page_len)s """.format(**{
|
||||||
'txt': "%%%s%%" % txt, '_txt': txt.replace("%", ""),
|
'field': fields,
|
||||||
'mcond':get_match_cond(doctype), 'start': start,
|
'key': searchfield,
|
||||||
'page_len': page_len})
|
'mcond':get_match_cond(doctype)
|
||||||
|
}), {
|
||||||
|
'txt': "%%%s%%" % txt,
|
||||||
|
'_txt': txt.replace("%", ""),
|
||||||
|
'start': start,
|
||||||
|
'page_len': page_len
|
||||||
|
})
|
||||||
|
|
||||||
def tax_account_query(doctype, txt, searchfield, start, page_len, filters):
|
def tax_account_query(doctype, txt, searchfield, start, page_len, filters):
|
||||||
tax_accounts = frappe.db.sql("""select name, parent_account from tabAccount
|
tax_accounts = frappe.db.sql("""select name, parent_account from tabAccount
|
||||||
|
Loading…
x
Reference in New Issue
Block a user