Skip to content

Commit

Permalink
Merge pull request #38268 from s-aga-r/FIX-38222
Browse files Browse the repository at this point in the history
fix: Supplier `Primary Contact`
  • Loading branch information
s-aga-r authored Nov 23, 2023
2 parents 880a85d + 627165d commit c99c805
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 c99c805

Please sign in to comment.