1
0
forked from test/crm

fix: hide or make field read only based on higher permlevel access

This commit is contained in:
Shariq Ansari 2024-02-29 16:28:36 +05:30
parent d145171e97
commit 2bc7a52365
3 changed files with 16 additions and 3 deletions

View File

@ -244,7 +244,7 @@ def get_list_data(
}
def get_doctype_fields(doctype):
def get_doctype_fields(doctype, name):
not_allowed_fieldtypes = [
"Section Break",
"Column Break",
@ -256,6 +256,12 @@ def get_doctype_fields(doctype):
sections = {}
section_fields = []
last_section = None
doc = frappe.get_cached_doc(doctype, name)
has_high_permlevel_fields = any(df.permlevel > 0 for df in fields)
if has_high_permlevel_fields:
has_read_access_to_permlevels = doc.get_permlevel_access("read")
has_write_access_to_permlevels = doc.get_permlevel_access("write")
for field in fields:
if field.fieldtype == "Tab Break" and last_section:
@ -277,6 +283,13 @@ def get_doctype_fields(doctype):
"fields": [],
}
else:
if field.permlevel > 0:
field_has_write_access = field.permlevel in has_write_access_to_permlevels
field_has_read_access = field.permlevel in has_read_access_to_permlevels
if not field_has_write_access and field_has_read_access:
field.read_only = 1
if not field_has_read_access and not field_has_write_access:
field.hidden = 1
section_fields.append(get_field_obj(field))
section_fields = []

View File

@ -27,7 +27,7 @@ def get_deal(name):
fields=["contact", "is_primary"],
)
deal["doctype_fields"], deal["all_fields"] = get_doctype_fields("CRM Deal")
deal["doctype_fields"], deal["all_fields"] = get_doctype_fields("CRM Deal", name)
deal["doctype"] = "CRM Deal"
deal["_form_script"] = get_form_script('CRM Deal')
deal["_assign"] = get_assigned_users("CRM Deal", deal.name)

View File

@ -15,7 +15,7 @@ def get_lead(name):
frappe.throw(_("Lead not found"), frappe.DoesNotExistError)
lead = lead.pop()
lead["doctype_fields"], lead["all_fields"] = get_doctype_fields("CRM Lead")
lead["doctype_fields"], lead["all_fields"] = get_doctype_fields("CRM Lead", name)
lead["doctype"] = "CRM Lead"
lead["_form_script"] = get_form_script('CRM Lead')
lead["_assign"] = get_assigned_users("CRM Lead", lead.name)