Merge pull request #57997 from kaulith/fix/bom-item-query-barcode-search

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

View File

@@ -158,9 +158,9 @@ def _item_query_filters(filters):
def _item_query_or_filters(txt, searchfields, query_filters):
if not txt:
return {}
return []
or_filters = {s_field: ("like", f"%{txt}%") for s_field in searchfields}
or_filters = [[s_field, "like", f"%{txt}%"] for s_field in searchfields]
barcodes = frappe.get_all(
"Item Barcode",
fields=["parent as item_code"],
@@ -169,7 +169,7 @@ def _item_query_or_filters(txt, searchfields, query_filters):
)
barcode_codes = [d.item_code for d in barcodes]
if barcode_codes:
or_filters["name"] = ("in", barcode_codes)
or_filters.append(["name", "in", barcode_codes])
return or_filters

View File

@@ -594,6 +594,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()