From c4e35ba5be6dca72181706c8fe98d97baffdf95c Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Mon, 1 Jul 2024 18:10:47 +0200 Subject: [PATCH] fix(Contact): set address query and buttons from links --- frappe/contacts/doctype/contact/contact.js | 41 ++++++++++++---------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/frappe/contacts/doctype/contact/contact.js b/frappe/contacts/doctype/contact/contact.js index 71571c79e5..39052178f5 100644 --- a/frappe/contacts/doctype/contact/contact.js +++ b/frappe/contacts/doctype/contact/contact.js @@ -60,25 +60,30 @@ frappe.ui.form.on("Contact", { }); } - if (frm.doc.links) { - frappe.call({ - method: "frappe.contacts.doctype.contact.contact.address_query", - args: { links: frm.doc.links }, - callback: function (r) { - if (r && r.message) { - frm.set_query("address", function () { - return { - filters: { - name: ["in", r.message], - }, - }; - }); - } - }, - }); + if (frm.doc.links && frm.doc.links.length > 0) { + const filtered_links = frm.doc.links.filter( + (link) => link.link_doctype && link.link_name + ); - for (let i in frm.doc.links) { - let link = frm.doc.links[i]; + if (filtered_links.length > 0) { + frappe.call({ + method: "frappe.contacts.doctype.contact.contact.address_query", + args: { links: filtered_links }, + callback: function (r) { + if (r && r.message) { + frm.set_query("address", function () { + return { + filters: { + name: ["in", r.message], + }, + }; + }); + } + }, + }); + } + + for (const link of filtered_links) { frm.add_custom_button( __("{0}: {1}", [__(link.link_doctype), __(link.link_name)]), function () {