Merge pull request #33254 from ruthra-kumar/index_error_on_customer_master
fix: index error on customer master
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index d0eb377..60c3356 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -6,7 +6,7 @@
import frappe
import frappe.defaults
-from frappe import _, msgprint
+from frappe import _, msgprint, qb
from frappe.contacts.address_and_contact import (
delete_contact_and_address,
load_address_and_contact,
@@ -732,12 +732,15 @@
@frappe.validate_and_sanitize_search_inputs
def get_customer_primary_contact(doctype, txt, searchfield, start, page_len, filters):
customer = filters.get("customer")
- return frappe.db.sql(
- """
- select `tabContact`.name from `tabContact`, `tabDynamic Link`
- where `tabContact`.name = `tabDynamic Link`.parent and `tabDynamic Link`.link_name = %(customer)s
- and `tabDynamic Link`.link_doctype = 'Customer'
- and `tabContact`.name like %(txt)s
- """,
- {"customer": customer, "txt": "%%%s%%" % txt},
+
+ con = qb.DocType("Contact")
+ dlink = qb.DocType("Dynamic Link")
+
+ return (
+ qb.from_(con)
+ .join(dlink)
+ .on(con.name == dlink.parent)
+ .select(con.name, con.full_name, con.email_id)
+ .where((dlink.link_name == customer) & (con.name.like(f"%{txt}%")))
+ .run()
)