Skip to content

Commit fe8bede

Browse files
authored
Merge pull request #57997 from kaulith/fix/bom-item-query-barcode-search
fix: keep item code searchable when a barcode matches the same text
2 parents 70f236a + 23024d1 commit fe8bede

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

erpnext/manufacturing/doctype/bom/mapper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ def _item_query_filters(filters):
158158

159159
def _item_query_or_filters(txt, searchfields, query_filters):
160160
if not txt:
161-
return {}
161+
return []
162162

163-
or_filters = {s_field: ("like", f"%{txt}%") for s_field in searchfields}
163+
or_filters = [[s_field, "like", f"%{txt}%"] for s_field in searchfields]
164164
barcodes = frappe.get_all(
165165
"Item Barcode",
166166
fields=["parent as item_code"],
@@ -169,7 +169,7 @@ def _item_query_or_filters(txt, searchfields, query_filters):
169169
)
170170
barcode_codes = [d.item_code for d in barcodes]
171171
if barcode_codes:
172-
or_filters["name"] = ("in", barcode_codes)
172+
or_filters.append(["name", "in", barcode_codes])
173173
return or_filters
174174

175175

erpnext/manufacturing/doctype/bom/test_bom.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,29 @@ def test_bom_item_query(self):
594594
self.assertNotEqual(len(test_items), len(filtered), msg="Item filtering showing excessive results")
595595
self.assertTrue(0 < len(filtered) <= 3, msg="Item filtering showing excessive results")
596596

597+
@timeout
598+
def test_bom_item_query_matches_item_code_colliding_with_another_barcode(self):
599+
item = make_item(
600+
"_Test BOM Query 2.5MM",
601+
{"is_stock_item": 1, "item_name": "_Test BOM Query Sheet", "description": "sheet"},
602+
)
603+
make_item(
604+
"_Test BOM Query Barcode Holder",
605+
{"is_stock_item": 1},
606+
barcode=f"90{item.name}90",
607+
)
608+
609+
results = item_query(
610+
doctype="Item",
611+
txt=item.name,
612+
searchfield="name",
613+
start=0,
614+
page_len=20,
615+
filters={"is_stock_item": 1},
616+
)
617+
618+
self.assertIn(item.name, [d[0] for d in results])
619+
597620
@timeout
598621
def test_exclude_exploded_items_from_bom(self):
599622
bom_no = get_default_bom()

0 commit comments

Comments
 (0)