From 3dbafe4bd940da16301d7a48bad3da2187113ef1 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Sun, 15 Sep 2019 15:06:02 +0530 Subject: [PATCH 1/3] feat: show address related to doctype in child --- frappe/contacts/doctype/contact/contact.js | 19 ++++++++++++++++++ frappe/contacts/doctype/contact/contact.py | 23 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/frappe/contacts/doctype/contact/contact.js b/frappe/contacts/doctype/contact/contact.js index 9e9b0248d9..5f13a55f5a 100644 --- a/frappe/contacts/doctype/contact/contact.js +++ b/frappe/contacts/doctype/contact/contact.js @@ -41,6 +41,25 @@ frappe.ui.form.on("Contact", { } }); frm.refresh_field("links"); + + if (frm.doc.links.length > 0) { + frappe.call({ + method: "frappe.contacts.doctype.contact.contact.address_query", + args: {links: frm.doc.links}, + callback: function(r) { + if (r && r.message) { + console.log(r.message); + frm.set_query("address", function () { + return { + filters: { + name: ["in", r.message], + } + } + }); + } + } + }); + } }, validate: function(frm) { // clear linked customer / supplier / sales partner on saving... diff --git a/frappe/contacts/doctype/contact/contact.py b/frappe/contacts/doctype/contact/contact.py index 6857d013a1..588e80def3 100644 --- a/frappe/contacts/doctype/contact/contact.py +++ b/frappe/contacts/doctype/contact/contact.py @@ -198,6 +198,29 @@ def contact_query(doctype, txt, searchfield, start, page_len, filters): 'link_doctype': link_doctype }) +@frappe.whitelist() +def address_query(links): + import json + + links = [{"link_doctype": d.get("link_doctype"), "link_name": d.get("link_name")} for d in json.loads(links)] + result = [] + + for link in links: + res = frappe.db.sql(""" + SELECT `tabAddress`.name + FROM `tabAddress`, `tabDynamic Link` + WHERE `tabDynamic Link`.parenttype='Address' + AND `tabDynamic Link`.parent=`tabAddress`.name + AND `tabDynamic Link`.link_doctype = %(link_doctype)s + AND `tabDynamic Link`.link_name = %(link_name)s + """, { + "link_doctype": link.get("link_doctype"), + "link_name": link.get("link_name"), + }, as_dict=True) + + result.extend([l.name for l in res]) + + return result def get_contact_with_phone_number(number): if not number: return From ccd2c101287edd20ed18513132a2461ff56f5691 Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Sun, 15 Sep 2019 17:46:53 +0530 Subject: [PATCH 2/3] chore: remove log statement --- frappe/contacts/doctype/contact/contact.js | 1 - 1 file changed, 1 deletion(-) diff --git a/frappe/contacts/doctype/contact/contact.js b/frappe/contacts/doctype/contact/contact.js index 5f13a55f5a..7bbbbb1564 100644 --- a/frappe/contacts/doctype/contact/contact.js +++ b/frappe/contacts/doctype/contact/contact.js @@ -48,7 +48,6 @@ frappe.ui.form.on("Contact", { args: {links: frm.doc.links}, callback: function(r) { if (r && r.message) { - console.log(r.message); frm.set_query("address", function () { return { filters: { From 7a25c26390fcbeac263109110049069708d1c28f Mon Sep 17 00:00:00 2001 From: Himanshu Warekar Date: Mon, 16 Sep 2019 10:02:43 +0530 Subject: [PATCH 3/3] fix: check for read permission --- frappe/contacts/doctype/contact/contact.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frappe/contacts/doctype/contact/contact.py b/frappe/contacts/doctype/contact/contact.py index 588e80def3..dac17f6772 100644 --- a/frappe/contacts/doctype/contact/contact.py +++ b/frappe/contacts/doctype/contact/contact.py @@ -206,6 +206,9 @@ def address_query(links): result = [] for link in links: + if not frappe.has_permission(doctype=link.get("link_doctype"), ptype="read", doc=link.get("link_name")): + continue + res = frappe.db.sql(""" SELECT `tabAddress`.name FROM `tabAddress`, `tabDynamic Link`