feat: show address related to doctype in child
This commit is contained in:
parent
f26c8895bd
commit
3dbafe4bd9
2 changed files with 42 additions and 0 deletions
|
|
@ -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...
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue