fix: Supplier Primary Contact (backport #38268) (#38286)

fix: Supplier `Primary Contact`

(cherry picked from commit 627165dc7c6c1cd83d746b97c82210abeb9a2e29)

Co-authored-by: s-aga-r <sagarsharma.s312@gmail.com>
This commit is contained in:
mergify[bot] 2023-11-23 11:13:32 +05:30 committed by GitHub
parent fb4235c528
commit 37d1f1ac67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -165,16 +165,17 @@ class Supplier(TransactionBase):
@frappe.validate_and_sanitize_search_inputs
def get_supplier_primary_contact(doctype, txt, searchfield, start, page_len, filters):
supplier = filters.get("supplier")
return frappe.db.sql(
"""
SELECT
`tabContact`.name from `tabContact`,
`tabDynamic Link`
WHERE
`tabContact`.name = `tabDynamic Link`.parent
and `tabDynamic Link`.link_name = %(supplier)s
and `tabDynamic Link`.link_doctype = 'Supplier'
and `tabContact`.name like %(txt)s
""",
{"supplier": supplier, "txt": "%%%s%%" % txt},
)
contact = frappe.qb.DocType("Contact")
dynamic_link = frappe.qb.DocType("Dynamic Link")
return (
frappe.qb.from_(contact)
.join(dynamic_link)
.on(contact.name == dynamic_link.parent)
.select(contact.name, contact.email_id)
.where(
(dynamic_link.link_name == supplier)
& (dynamic_link.link_doctype == "Supplier")
& (contact.name.like("%{0}%".format(txt)))
)
).run(as_dict=False)