From ae8aa7624648637e6506c9384fd0d9ef6702ac88 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Thu, 27 Apr 2017 16:48:51 +0530 Subject: [PATCH] Dynamic link validation, sort the sequence of the doctypes based on the field User Cannot Search (#3173) * Ignore dynamic link validation for the doctypes, which has permission do not search and view by the users * fix test cases * Update * Update dynamic_links.py * Update dynamic_links.py --- frappe/model/dynamic_links.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/frappe/model/dynamic_links.py b/frappe/model/dynamic_links.py index d68c60a2b1..0932ffa623 100644 --- a/frappe/model/dynamic_links.py +++ b/frappe/model/dynamic_links.py @@ -3,9 +3,24 @@ import frappe +# select doctypes that are accessed by the user (not read_only) first, so that the +# the validation message shows the user-facing doctype first. +# For example Journal Entry should be validated before GL Entry (which is an internal doctype) + dynamic_link_queries = [ - """select parent, fieldname, options from tabDocField where fieldtype='Dynamic Link'""", - """select dt as parent, fieldname, options from `tabCustom Field` where fieldtype='Dynamic Link'""", + """select parent, + (select read_only from `tabDocType` where name=tabDocField.parent) as read_only, + fieldname, options + from tabDocField + where fieldtype='Dynamic Link' + order by read_only""", + + """select dt as parent, + (select read_only from `tabDocType` where name=`tabCustom Field`.dt) as read_only, + fieldname, options + from `tabCustom Field` + where fieldtype='Dynamic Link' + order by read_only""", ] def get_dynamic_link_map(for_delete=False): @@ -29,7 +44,6 @@ def get_dynamic_link_map(for_delete=False): dynamic_link_map.setdefault(doctype, []).append(df) frappe.local.dynamic_link_map = dynamic_link_map - return frappe.local.dynamic_link_map def get_dynamic_links():