Merge pull request #32414 from rohitwaghchaure/consider-searchfields-as-per-customize-form
fix: searchfields as per customize form not working for Item
This commit is contained in:
commit
10b7592d14
@ -212,21 +212,15 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals
|
|||||||
meta = frappe.get_meta(doctype, cached=True)
|
meta = frappe.get_meta(doctype, cached=True)
|
||||||
searchfields = meta.get_search_fields()
|
searchfields = meta.get_search_fields()
|
||||||
|
|
||||||
# these are handled separately
|
|
||||||
ignored_search_fields = ("item_name", "description")
|
|
||||||
for ignored_field in ignored_search_fields:
|
|
||||||
if ignored_field in searchfields:
|
|
||||||
searchfields.remove(ignored_field)
|
|
||||||
|
|
||||||
columns = ""
|
columns = ""
|
||||||
extra_searchfields = [
|
extra_searchfields = [field for field in searchfields if not field in ["name", "description"]]
|
||||||
field
|
|
||||||
for field in searchfields
|
|
||||||
if not field in ["name", "item_group", "description", "item_name"]
|
|
||||||
]
|
|
||||||
|
|
||||||
if extra_searchfields:
|
if extra_searchfields:
|
||||||
columns = ", " + ", ".join(extra_searchfields)
|
columns += ", " + ", ".join(extra_searchfields)
|
||||||
|
|
||||||
|
if "description" in searchfields:
|
||||||
|
columns += """, if(length(tabItem.description) > 40, \
|
||||||
|
concat(substr(tabItem.description, 1, 40), "..."), description) as description"""
|
||||||
|
|
||||||
searchfields = searchfields + [
|
searchfields = searchfields + [
|
||||||
field
|
field
|
||||||
@ -266,12 +260,10 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals
|
|||||||
if frappe.db.count(doctype, cache=True) < 50000:
|
if frappe.db.count(doctype, cache=True) < 50000:
|
||||||
# scan description only if items are less than 50000
|
# scan description only if items are less than 50000
|
||||||
description_cond = "or tabItem.description LIKE %(txt)s"
|
description_cond = "or tabItem.description LIKE %(txt)s"
|
||||||
|
|
||||||
return frappe.db.sql(
|
return frappe.db.sql(
|
||||||
"""select
|
"""select
|
||||||
tabItem.name, tabItem.item_name, tabItem.item_group,
|
tabItem.name {columns}
|
||||||
if(length(tabItem.description) > 40, \
|
|
||||||
concat(substr(tabItem.description, 1, 40), "..."), description) as description
|
|
||||||
{columns}
|
|
||||||
from tabItem
|
from tabItem
|
||||||
where tabItem.docstatus < 2
|
where tabItem.docstatus < 2
|
||||||
and tabItem.disabled=0
|
and tabItem.disabled=0
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
|
||||||
from frappe.test_runner import make_test_objects
|
from frappe.test_runner import make_test_objects
|
||||||
from frappe.tests.utils import FrappeTestCase, change_settings
|
from frappe.tests.utils import FrappeTestCase, change_settings
|
||||||
from frappe.utils import add_days, today
|
from frappe.utils import add_days, today
|
||||||
@ -816,6 +817,30 @@ class TestItem(FrappeTestCase):
|
|||||||
item.reload()
|
item.reload()
|
||||||
self.assertEqual(item.is_stock_item, 1)
|
self.assertEqual(item.is_stock_item, 1)
|
||||||
|
|
||||||
|
def test_serach_fields_for_item(self):
|
||||||
|
from erpnext.controllers.queries import item_query
|
||||||
|
|
||||||
|
make_property_setter("Item", None, "search_fields", "item_name", "Data", for_doctype="Doctype")
|
||||||
|
|
||||||
|
item = make_item(properties={"item_name": "Test Item", "description": "Test Description"})
|
||||||
|
data = item_query(
|
||||||
|
"Item", "Test Item", "", 0, 20, filters={"item_name": "Test Item"}, as_dict=True
|
||||||
|
)
|
||||||
|
self.assertEqual(data[0].name, item.name)
|
||||||
|
self.assertEqual(data[0].item_name, item.item_name)
|
||||||
|
self.assertTrue("description" not in data[0])
|
||||||
|
|
||||||
|
make_property_setter(
|
||||||
|
"Item", None, "search_fields", "item_name, description", "Data", for_doctype="Doctype"
|
||||||
|
)
|
||||||
|
data = item_query(
|
||||||
|
"Item", "Test Item", "", 0, 20, filters={"item_name": "Test Item"}, as_dict=True
|
||||||
|
)
|
||||||
|
self.assertEqual(data[0].name, item.name)
|
||||||
|
self.assertEqual(data[0].item_name, item.item_name)
|
||||||
|
self.assertEqual(data[0].description, item.description)
|
||||||
|
self.assertTrue("description" in data[0])
|
||||||
|
|
||||||
|
|
||||||
def set_item_variant_settings(fields):
|
def set_item_variant_settings(fields):
|
||||||
doc = frappe.get_doc("Item Variant Settings")
|
doc = frappe.get_doc("Item Variant Settings")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user