fix: MR Default Supplier search query
diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py
index 02fbd3d..ace84f8 100644
--- a/erpnext/stock/doctype/material_request/material_request.py
+++ b/erpnext/stock/doctype/material_request/material_request.py
@@ -595,17 +595,28 @@
for d in doc.items:
item_list.append(d.item_code)
- return frappe.db.sql(
- """select default_supplier
- from `tabItem Default`
- where parent in ({0}) and
- default_supplier IS NOT NULL
- """.format(
- ", ".join(["%s"] * len(item_list))
- ),
- tuple(item_list),
+ supplier = frappe.qb.DocType("Supplier")
+ item_default = frappe.qb.DocType("Item Default")
+ query = (
+ frappe.qb.from_(supplier)
+ .left_join(item_default)
+ .on(supplier.name == item_default.default_supplier)
+ .select(item_default.default_supplier)
+ .where(
+ (item_default.parent.isin(item_list))
+ & (item_default.default_supplier.notnull())
+ & (supplier[searchfield].like(f"%{txt}%"))
+ )
+ .offset(start)
+ .limit(page_len)
)
+ meta = frappe.get_meta("Supplier")
+ if meta.show_title_field_in_link and meta.title_field:
+ query = query.select(supplier[meta.title_field])
+
+ return query.run(as_dict=False)
+
@frappe.whitelist()
def make_supplier_quotation(source_name, target_doc=None):