mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-12 22:21:50 +00:00
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:
@@ -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")
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user