Merge pull request #8423 from hrwX/addr_query

feat(Contact): Show address related to doctype in child
This commit is contained in:
mergify[bot] 2019-09-16 09:38:43 +00:00 committed by GitHub
commit bde6d31dec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

View file

@ -41,6 +41,24 @@ 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) {
frm.set_query("address", function () {
return {
filters: {
name: ["in", r.message],
}
}
});
}
}
});
}
},
validate: function(frm) {
// clear linked customer / supplier / sales partner on saving...

View file

@ -198,6 +198,32 @@ 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:
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`
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