From d073b005a8579e48266d1265ccf542f625ac595b Mon Sep 17 00:00:00 2001 From: venkat102 Date: Wed, 27 Nov 2024 14:02:11 +0530 Subject: [PATCH] fix: filter item with search fields (cherry picked from commit ebfbee3da50961019691d650d7d152502d541094) --- .../doctype/product_bundle/product_bundle.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/erpnext/selling/doctype/product_bundle/product_bundle.py b/erpnext/selling/doctype/product_bundle/product_bundle.py index 464cff01d7e..609f45a608f 100644 --- a/erpnext/selling/doctype/product_bundle/product_bundle.py +++ b/erpnext/selling/doctype/product_bundle/product_bundle.py @@ -5,6 +5,7 @@ import frappe from frappe import _ from frappe.model.document import Document +from frappe.query_builder import Criterion from frappe.utils import get_link_to_form @@ -93,15 +94,24 @@ class ProductBundle(Document): def get_new_item_code(doctype, txt, searchfield, start, page_len, filters): product_bundles = frappe.db.get_list("Product Bundle", {"disabled": 0}, pluck="name") + if not searchfield or searchfield == "name": + searchfield = frappe.get_meta("Item").get("search_fields") + + searchfield = searchfield.split(",") + searchfield.append("name") + item = frappe.qb.DocType("Item") query = ( frappe.qb.from_(item) - .select(item.item_code, item.item_name) - .where((item.is_stock_item == 0) & (item.is_fixed_asset == 0) & (item[searchfield].like(f"%{txt}%"))) + .select(item.name, item.item_name) + .where((item.is_stock_item == 0) & (item.is_fixed_asset == 0)) .limit(page_len) .offset(start) ) + if searchfield: + query = query.where(Criterion.any([item[fieldname].like(f"%{txt}%") for fieldname in searchfield])) + if product_bundles: query = query.where(item.name.notin(product_bundles))