Merge pull request #58002 from frappe/mergify/bp/version-16-hotfix/pr-57997

fix: keep item code searchable when a barcode matches the same text (backport #57997)
This commit is contained in:
Mihir Kandoi
2026-08-11 12:42:51 +05:30
committed by GitHub
2 changed files with 26 additions and 3 deletions

View File

@@ -1909,10 +1909,10 @@ def item_query(doctype, txt, searchfield, start, page_len, filters):
[IfNull(Field("end_of_life"), "3099-12-31"), ">", today()],
]
or_cond_filters = {}
or_cond_filters = []
if txt:
for s_field in searchfields:
or_cond_filters[s_field] = ("like", f"%{txt}%")
or_cond_filters.append([s_field, "like", f"%{txt}%"])
barcodes = frappe.get_all(
"Item Barcode",
@@ -1923,7 +1923,7 @@ def item_query(doctype, txt, searchfield, start, page_len, filters):
barcodes = [d.item_code for d in barcodes]
if barcodes:
or_cond_filters["name"] = ("in", barcodes)
or_cond_filters.append(["name", "in", barcodes])
if filters and filters.get("item_code"):
has_variants = frappe.get_cached_value("Item", filters.get("item_code"), "has_variants")

View File

@@ -486,6 +486,29 @@ class TestBOM(ERPNextTestSuite):
self.assertNotEqual(len(test_items), len(filtered), msg="Item filtering showing excessive results")
self.assertTrue(0 < len(filtered) <= 3, msg="Item filtering showing excessive results")
@timeout
def test_bom_item_query_matches_item_code_colliding_with_another_barcode(self):
item = make_item(
"_Test BOM Query 2.5MM",
{"is_stock_item": 1, "item_name": "_Test BOM Query Sheet", "description": "sheet"},
)
make_item(
"_Test BOM Query Barcode Holder",
{"is_stock_item": 1},
barcode=f"90{item.name}90",
)
results = item_query(
doctype="Item",
txt=item.name,
searchfield="name",
start=0,
page_len=20,
filters={"is_stock_item": 1},
)
self.assertIn(item.name, [d[0] for d in results])
@timeout
def test_exclude_exploded_items_from_bom(self):
bom_no = get_default_bom()