[minor] filters for both address and contact dynamic link lin_doctype field

This commit is contained in:
mbauskar 2017-03-07 17:17:14 +05:30
parent 6f9016ab13
commit 0bd9f37ebe
4 changed files with 45 additions and 12 deletions

View file

@ -29,7 +29,15 @@ frappe.ui.form.on("Contact", {
});
});
}
cur_frm.set_query("link_doctype", "links", "frappe.email.doctype.contact.contact.contact_links")
frm.set_query('link_doctype', "links", function() {
return {
query: "frappe.geo.address_and_contact.filter_dynamic_link_doctypes",
filters: {
fieldtype: "Link",
options: frm.doc.doctype,
}
}
});
},
validate: function(frm) {
// clear linked customer / supplier / sales partner on saving...
@ -40,6 +48,7 @@ frappe.ui.form.on("Contact", {
}
}
});
frappe.ui.form.on("Dynamic Link", {
link_name:function(frm, cdt, cdn){
var child = locals[cdt][cdn];

View file

@ -149,13 +149,3 @@ def contact_query(doctype, txt, searchfield, start, page_len, filters):
'link_name': link_name,
'link_doctype': link_doctype
})
def contact_links(doctype, txt, searchfield, start, page_len, filters):
if not txt: txt = ""
txt = txt.lower()
return [[d] for d in get_link_doctypes() if txt in d.lower()]
@frappe.whitelist()
def get_link_doctypes():
return [x.parent for x in frappe.db.get_values("DocField", {"fieldname": 'contact_html'}, "parent", order_by="name", as_dict=1)]

View file

@ -138,4 +138,29 @@ def delete_contact_and_address(doctype, docname):
for name in items:
doc = frappe.get_doc(parenttype, name)
if len(doc.links)==1:
doc.delete()
doc.delete()
def filter_dynamic_link_doctypes(doctype, txt, searchfield, start, page_len, filters):
if not txt: txt = ""
txt = txt.lower()
txt = "%%%s%%" % (txt)
filters.update({
"parent": ("like", txt)
})
doctypes = frappe.db.get_all("DocField", filters=filters, fields=["parent"],
order_by="parent asc", distinct=True, as_list=True)
filters.pop("parent")
filters.update({
"dt": ("not in", [doctype[0] for doctype in doctypes]),
"dt": ("like", txt),
})
_doctypes = frappe.db.get_all("Custom Field", filters=filters, fields=["dt"],
order_by="dt asc", as_list=True)
all_doctypes = doctypes + _doctypes
return sorted(all_doctypes, key=lambda item: item[0])

View file

@ -13,6 +13,15 @@ frappe.ui.form.on("Address", {
});
}
}
frm.set_query('link_doctype', "links", function() {
return {
query: "frappe.geo.address_and_contact.filter_dynamic_link_doctypes",
filters: {
fieldtype: "Link",
options: frm.doc.doctype,
}
}
});
},
validate: function(frm) {
// clear linked customer / supplier / sales partner on saving...