fix: filter item with search fields
(cherry picked from commit ebfbee3da5)
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe.query_builder import Criterion
|
||||||
from frappe.utils import get_link_to_form
|
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):
|
def get_new_item_code(doctype, txt, searchfield, start, page_len, filters):
|
||||||
product_bundles = frappe.db.get_list("Product Bundle", {"disabled": 0}, pluck="name")
|
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")
|
item = frappe.qb.DocType("Item")
|
||||||
query = (
|
query = (
|
||||||
frappe.qb.from_(item)
|
frappe.qb.from_(item)
|
||||||
.select(item.item_code, item.item_name)
|
.select(item.name, item.item_name)
|
||||||
.where((item.is_stock_item == 0) & (item.is_fixed_asset == 0) & (item[searchfield].like(f"%{txt}%")))
|
.where((item.is_stock_item == 0) & (item.is_fixed_asset == 0))
|
||||||
.limit(page_len)
|
.limit(page_len)
|
||||||
.offset(start)
|
.offset(start)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if searchfield:
|
||||||
|
query = query.where(Criterion.any([item[fieldname].like(f"%{txt}%") for fieldname in searchfield]))
|
||||||
|
|
||||||
if product_bundles:
|
if product_bundles:
|
||||||
query = query.where(item.name.notin(product_bundles))
|
query = query.where(item.name.notin(product_bundles))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user