diff --git a/frappe/core/doctype/dynamic_link/dynamic_link.json b/frappe/core/doctype/dynamic_link/dynamic_link.json index cde3702896..fbdbbf76cb 100644 --- a/frappe/core/doctype/dynamic_link/dynamic_link.json +++ b/frappe/core/doctype/dynamic_link/dynamic_link.json @@ -68,6 +68,34 @@ "search_index": 0, "set_only_once": 0, "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "link_title", + "fieldtype": "Read Only", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "Link Title", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 1, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 } ], "hide_heading": 0, @@ -80,7 +108,7 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2017-01-13 04:55:18.835023", + "modified": "2017-01-17 14:25:49.140730", "modified_by": "Administrator", "module": "Core", "name": "Dynamic Link", diff --git a/frappe/email/doctype/contact/contact.js b/frappe/email/doctype/contact/contact.js index b1f19dc7ed..0c7ef40f2b 100644 --- a/frappe/email/doctype/contact/contact.js +++ b/frappe/email/doctype/contact/contact.js @@ -29,6 +29,15 @@ frappe.ui.form.on("Contact", { }); }); } + 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... @@ -38,4 +47,18 @@ frappe.ui.form.on("Contact", { }); } } -}); \ No newline at end of file +}); + +frappe.ui.form.on("Dynamic Link", { + link_name:function(frm, cdt, cdn){ + var child = locals[cdt][cdn]; + if(child.link_name) { + frappe.model.with_doctype(child.link_doctype, function () { + var title_field = frappe.get_meta(child.link_doctype).title_field || "name" + frappe.model.get_value(child.link_doctype, child.link_name, title_field, function (r) { + frappe.model.set_value(cdt, cdn, "link_title", r[title_field]) + }) + }) + } + } +}) diff --git a/frappe/geo/address_and_contact.py b/frappe/geo/address_and_contact.py index 8f6bc3fdf7..717471dbd1 100644 --- a/frappe/geo/address_and_contact.py +++ b/frappe/geo/address_and_contact.py @@ -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() \ No newline at end of file + 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]) \ No newline at end of file diff --git a/frappe/geo/doctype/address/address.js b/frappe/geo/doctype/address/address.js index aff7b85860..41691e03fe 100644 --- a/frappe/geo/doctype/address/address.js +++ b/frappe/geo/doctype/address/address.js @@ -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...