This question has been flagged
3 Replies
6623 Views

In v13, if user is related to an emplyee, and I g to My profile, gives the following error. I.e, user needs to be HR/Offices to be able to access "My profile", which is certainly wrong.

These fields are on hr.employee model, so basically I see the reason for the restriction, but in this use case this does not work at all.

The requested operation can not be completed due to security restrictions. Document type: Users (res.users) Operation: read User: 9 Fields: - address_home_id (allowed for groups 'Employees / Officer') ...

Avatar
Discard

Hi, May I know if this issue can fix by any solutions?

I met the same issue, who can fix it?

This helped alot..

Best Answer

Hello.

We recently encountered the same error on one of our production databases. After a little bit of analysis, we realized we were adding a field on the res.users model and added this field on the inherited form view base.view_users_form_simple_modif in a custom module. 

What happens is that Odoo hr module introduces a new view on the res.users model to allow any user to visualize any private information on the employee connected to their user from the “My profile” view and this new hr view res_users_view_form_simple_modif inherits in mode primary from the base.view_users_form_simple_modif. Inheriting in mode primary allows the base view to be extended from other modules but still add the same edits on the hr extended view.

When the hr module is installed the base view is automatically overridden by the hr view, res_users_view_form_simple_modif and looks for which fields are accessible on the res.users model. Thus, res.users must override the __init__() method to add the field to the list of readable and writable fields in res.users. How the override of __init__ was done was looked up in the module mail (where it is done way more simply than how it is done in the hr module).

I  suggest having a look at these commits on github relative to the hr module to better understand why it works like that: 

  • https://github.com/odoo/odoo/commit/d77ce4c2a92c1da48150e4e84b714dd93f64847d
  • https://github.com/odoo/odoo/commit/c9ca3761464413327d2beb697553a3ccd7eef4d1

So our solution was:


res_users.py  
new_field = fields.Boolean(string="Our New Field", default=False)
def __init__(self, pool, cr):
# Override of __init__ to add access rights on new_field.             
# Access rights are disabled by default, but allowed            
# on some specific fields defined in self.SELF_{READ/WRITE}ABLE_FIELDS.  
init_res = super(Users, self).__init__(pool, cr)        
# duplicate list to avoid modifying the original reference        
type(self).SELF_WRITEABLE_FIELDS = list(self.SELF_WRITEABLE_FIELDS)        
type(self).SELF_WRITEABLE_FIELDS.extend(['new_field'])        
# duplicate list to avoid modifying the original reference        
type(self).SELF_READABLE_FIELDS = list(self.SELF_READABLE_FIELDS)        
type(self).SELF_READABLE_FIELDS.extend(['new_field'])        
return init_res

res_users.xml
inherit on view ref="base.view_users_form_simple_modif" (for my profile)
and on view ref="base.view_users_form" (for general settings > users)


Avatar
Discard

This helped, however I'm still having issues with saving of the data, even though its been added to writeable_fields...strange

Hello @Cameron P, are you still encountering some error? Or it just doesn't save at all?

I'm so grateful, it helped a lot. Thank you so much

Hello, What can I do in case of adding two fields ?
I tried adding my two fields to the extend method like this
profession = fields.Char(String="Profession")
titre = fields.Char(string="Titre")
and in the init method we have:
init_res = super(user, self).__init__(pool, cr)
# duplicate list to avoid modifying the original reference
type(self).SELF_WRITEABLE_FIELDS = list(self.SELF_WRITEABLE_FIELDS)
type(self).SELF_WRITEABLE_FIELDS.extend(['profession', 'titre'])
type(self).SELF_READABLE_FIELDS = list(self.SELF_READABLE_FIELDS)
type(self).SELF_READABLE_FIELDS.extend(['profession', 'titre'])

and of course added the two new fields in the specified inherited views, your method works pretty fine for one field, but when I tried adding one second field, I get the access right error, I would be grateful if you can help me with this

Hello, @Asma Ben Brahem as far as I can tell it seems you defined everything I expected, except maybe the return of the function (unless you just didn't copy it to your comment). Have you tried checking out the original code in the mail module here and make sure everything reflects how odoo expects it? https://github.com/odoo/odoo/blob/deaf27a75b0b123636066679dd14ef6b62541091/addons/mail/models/res_users.py#L68

Thank you! We indeed added a field to users model and installed the hr module. And could solve the conflict with the instructions above.

In Odoo 16, I had to change __init__(self, pool, cr) to __init__(self, *args) and super().__init__(*args) repectively. There are more arguments now.

Best Answer

Did you find a solution? I have the same problem and I can't resolve it :S

Avatar
Discard
Best Answer


Did you tried after checked the 'Employee Edition'?
Settings --> Employee Tab


Avatar
Discard