Skip to content

Commit

Permalink
fix: Supplier Primary Contact (backport #38268) (#38286)
Browse files Browse the repository at this point in the history
fix: Supplier `Primary Contact`

(cherry picked from commit 627165d)

Co-authored-by: s-aga-r <[email protected]>
  • Loading branch information
mergify[bot] and s-aga-r authored Nov 23, 2023
1 parent fb4235c commit 37d1f1a
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions erpnext/buying/doctype/supplier/supplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,17 @@ def after_rename(self, olddn, newdn, merge=False):
@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)

0 comments on commit 37d1f1a

Please sign in to comment.