From cf1e3dc8eac0df6731c333ad207cfeece514b8ab Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Tue, 6 Dec 2022 17:13:11 +0530 Subject: [PATCH] fix: index error on customer master --- erpnext/selling/doctype/customer/customer.py | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index d0eb3774e2..60c33567be 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -6,7 +6,7 @@ import json 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 @@ def make_address(args, is_primary_address=1): @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() )