From 4bc28f56bdffc066ded55dbf694f0c576e863bd1 Mon Sep 17 00:00:00 2001 From: robert schouten Date: Tue, 17 Jan 2017 16:49:03 +0800 Subject: [PATCH 1/2] contact only available on doctypes with contact_html --- .../doctype/dynamic_link/dynamic_link.json | 30 ++++++++++++++++++- frappe/email/doctype/contact/contact.js | 16 +++++++++- frappe/email/doctype/contact/contact.py | 10 +++++++ 3 files changed, 54 insertions(+), 2 deletions(-) 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..c550e99cd8 100644 --- a/frappe/email/doctype/contact/contact.js +++ b/frappe/email/doctype/contact/contact.js @@ -29,6 +29,7 @@ frappe.ui.form.on("Contact", { }); }); } + cur_frm.set_query("link_doctype", "links", "frappe.email.doctype.contact.contact.contact_links") }, validate: function(frm) { // clear linked customer / supplier / sales partner on saving... @@ -38,4 +39,17 @@ 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/email/doctype/contact/contact.py b/frappe/email/doctype/contact/contact.py index 1010fcff35..cb3179e273 100644 --- a/frappe/email/doctype/contact/contact.py +++ b/frappe/email/doctype/contact/contact.py @@ -135,3 +135,13 @@ def contact_query(doctype, txt, searchfield, start, page_len, filters): 'link_doctype': filters.get('link_doctype'), 'link_name': filters.get('link_name') }) + +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)] + From 0bd9f37ebe091bd68173ddde19d11ea0edbdec5d Mon Sep 17 00:00:00 2001 From: mbauskar Date: Tue, 7 Mar 2017 17:17:14 +0530 Subject: [PATCH 2/2] [minor] filters for both address and contact dynamic link lin_doctype field --- frappe/email/doctype/contact/contact.js | 11 +++++++++- frappe/email/doctype/contact/contact.py | 10 --------- frappe/geo/address_and_contact.py | 27 ++++++++++++++++++++++++- frappe/geo/doctype/address/address.js | 9 +++++++++ 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/frappe/email/doctype/contact/contact.js b/frappe/email/doctype/contact/contact.js index c550e99cd8..0c7ef40f2b 100644 --- a/frappe/email/doctype/contact/contact.js +++ b/frappe/email/doctype/contact/contact.js @@ -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]; diff --git a/frappe/email/doctype/contact/contact.py b/frappe/email/doctype/contact/contact.py index 107b476a55..6f24165c81 100644 --- a/frappe/email/doctype/contact/contact.py +++ b/frappe/email/doctype/contact/contact.py @@ -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)] - 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...