Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading