I want to do readonly all fields on project.task except description, What is best practice to do,
This is my code,
def write(self, vals):
fields_to_check_access = ['name', 'project_id', 'planned_date_begin', 'planned_date_end', 'recurrence_id',
'recurring_task', 'recurring_count', 'repeat_interval', 'repeat_unit', 'repeat_type',
'repeat_until', 'child_ids', 'parent_id', 'sequence', 'email_cc',
'displayed_image_id', 'date_deadline', 'tag_ids']
if self.project_id and self.project_id.is_office_project:
try:
if all(e in fields_to_check_access for e in vals):
self.check_access_rule('unlink')
except AccessError:
user_description = f"{self.env.user.name} (id={self.env.user.id})"
operation_error = _("Uh-oh! Looks like you have stumbled upon some top-secret records.\n\n" \
"Sorry, %s doesn't have write access to Tasks:", user_description)
failing_model = _("- %s (%s)", 'Task', 'project.task')
resolution_info = _(
"If you really, really need access, perhaps you can win over your friendly administrator with a batch of freshly baked cookies.")
raise AccessError(f"{operation_error}\n{failing_model}\n\n{resolution_info}")
return super(Task, self).write(vals)
I made a record rule for a specific group for unlink, and I am using that for write aswell.
In write function I am checking and I initialized some fields to check access, if changed field lies in those fields then I am just promting out the warning.
I want best practise to do this.
Thanks in advance.