diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 06f7ff894d6..aa010590bc5 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -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") diff --git a/erpnext/manufacturing/doctype/bom/test_bom.py b/erpnext/manufacturing/doctype/bom/test_bom.py index 48eb41fdb11..9d46906d621 100644 --- a/erpnext/manufacturing/doctype/bom/test_bom.py +++ b/erpnext/manufacturing/doctype/bom/test_bom.py @@ -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()