fix: Search field entries included in Item Link field query
This commit is contained in:
parent
213785e6d5
commit
3dbef9de74
@ -152,6 +152,17 @@ def tax_account_query(doctype, txt, searchfield, start, page_len, filters):
|
|||||||
def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=False):
|
def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=False):
|
||||||
conditions = []
|
conditions = []
|
||||||
|
|
||||||
|
#Get searchfields from meta and use in Item Link field query
|
||||||
|
meta = frappe.get_meta("Item")
|
||||||
|
searchfields = meta.get_search_fields()
|
||||||
|
|
||||||
|
fields = [f for f in searchfields if not f in ["name", "item_group", "description"]]
|
||||||
|
fields = ", ".join(fields)
|
||||||
|
|
||||||
|
searchfields = searchfields + [f for f in [searchfield or "name", "item_code", "item_group", "item_name"]
|
||||||
|
if not f in searchfields]
|
||||||
|
searchfields = " or ".join([field + " like %(txt)s" for field in searchfields])
|
||||||
|
|
||||||
description_cond = ''
|
description_cond = ''
|
||||||
if frappe.db.count('Item', cache=True) < 50000:
|
if frappe.db.count('Item', cache=True) < 50000:
|
||||||
# scan description only if items are less than 50000
|
# scan description only if items are less than 50000
|
||||||
@ -162,17 +173,14 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals
|
|||||||
concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name,
|
concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name,
|
||||||
tabItem.item_group,
|
tabItem.item_group,
|
||||||
if(length(tabItem.description) > 40, \
|
if(length(tabItem.description) > 40, \
|
||||||
concat(substr(tabItem.description, 1, 40), "..."), description) as decription
|
concat(substr(tabItem.description, 1, 40), "..."), description) as description,
|
||||||
|
{fields}
|
||||||
from tabItem
|
from tabItem
|
||||||
where tabItem.docstatus < 2
|
where tabItem.docstatus < 2
|
||||||
and tabItem.has_variants=0
|
and tabItem.has_variants=0
|
||||||
and tabItem.disabled=0
|
and tabItem.disabled=0
|
||||||
and (tabItem.end_of_life > %(today)s or ifnull(tabItem.end_of_life, '0000-00-00')='0000-00-00')
|
and (tabItem.end_of_life > %(today)s or ifnull(tabItem.end_of_life, '0000-00-00')='0000-00-00')
|
||||||
and (tabItem.`{key}` LIKE %(txt)s
|
and ({scond} or tabItem.item_code IN (select parent from `tabItem Barcode` where barcode LIKE %(txt)s)
|
||||||
or tabItem.item_code LIKE %(txt)s
|
|
||||||
or tabItem.item_group LIKE %(txt)s
|
|
||||||
or tabItem.item_name LIKE %(txt)s
|
|
||||||
or tabItem.item_code IN (select parent from `tabItem Barcode` where barcode LIKE %(txt)s)
|
|
||||||
{description_cond})
|
{description_cond})
|
||||||
{fcond} {mcond}
|
{fcond} {mcond}
|
||||||
order by
|
order by
|
||||||
@ -182,6 +190,8 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals
|
|||||||
name, item_name
|
name, item_name
|
||||||
limit %(start)s, %(page_len)s """.format(
|
limit %(start)s, %(page_len)s """.format(
|
||||||
key=searchfield,
|
key=searchfield,
|
||||||
|
fields=fields,
|
||||||
|
scond=searchfields,
|
||||||
fcond=get_filters_cond(doctype, filters, conditions).replace('%', '%%'),
|
fcond=get_filters_cond(doctype, filters, conditions).replace('%', '%%'),
|
||||||
mcond=get_match_cond(doctype).replace('%', '%%'),
|
mcond=get_match_cond(doctype).replace('%', '%%'),
|
||||||
description_cond = description_cond),
|
description_cond = description_cond),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user