@@ -8,6 +8,10 @@ def get_allowed_fieldnames_for_doctype(doctype: str, parent_doctype: str = None)
88 Gets a list of fieldnames that's allowed for the current User to
99 read on the specified doctype. This includes default_fields
1010 """
11+ _from_locals = _get_allowed_fieldnames_from_locals (doctype , parent_doctype )
12+ if _from_locals is not None :
13+ return _from_locals
14+
1115 fieldnames = list (default_fields )
1216 fieldnames .remove ("doctype" )
1317
@@ -25,6 +29,12 @@ def get_allowed_fieldnames_for_doctype(doctype: str, parent_doctype: str = None)
2529
2630 fieldnames .append (df .fieldname )
2731
32+ _set_allowed_fieldnames_to_locals (
33+ allowed_fields = fieldnames ,
34+ doctype = doctype ,
35+ parent_doctype = parent_doctype
36+ )
37+
2838 return fieldnames
2939
3040
@@ -45,3 +55,30 @@ def _get_permlevel_read_access(meta: Meta):
4555 _has_access_to .append (perm .get ("permlevel" ))
4656
4757 return _has_access_to
58+
59+
60+ def _get_allowed_fieldnames_from_locals (doctype : str , parent_doctype : str = None ):
61+
62+ if not hasattr (frappe .local , "permlevel_fields" ):
63+ frappe .local .permlevel_fields = dict ()
64+
65+ k = doctype
66+ if parent_doctype :
67+ k = (doctype , parent_doctype )
68+
69+ return frappe .local .permlevel_fields .get (k )
70+
71+
72+ def _set_allowed_fieldnames_to_locals (
73+ allowed_fields : List [str ],
74+ doctype : str ,
75+ parent_doctype : str = None ):
76+
77+ if not hasattr (frappe .local , "permlevel_fields" ):
78+ frappe .local .permlevel_fields = dict ()
79+
80+ k = doctype
81+ if parent_doctype :
82+ k = (doctype , parent_doctype )
83+
84+ frappe .local .permlevel_fields [k ] = allowed_fields
0 commit comments