In Odoo 12 you can check whether a user is in an access group by using self.env.user.has_group.
For example, I can set up a boolean computed field that is True if the user is in a user access group:
for record in self:
if self.env.user.has_group('<UserAccessGroup>'):
record['x_studio_authorization1'] = True
But in Odoo 13 this gives an error message for users who are not in the user access group. It's just a dialog box with the heading "Something went wrong" followed by the Model, ID & Field.
product.template(23,).x_studio_authorization1
As noted below in the comments, this error only happens if the computed field is NOT defined as "stored", which seems to be different from Odoo 12. The problem is that if the field is stored it doesn't work (because it doesn't get updated).
I see self.env.user.has_group('group') in loads of default Odoo modules though. Are you sure its not your record[{x_studio_authorization1'] = True that is failing?
Hi Yenthe
Quite possibly, but I don't know because the error message gives me no information! How can I check?
Here the record is an object and you are trying to get a value like dict syntax. Try to access record.field_name
Has this changed in Odoo 13? The same syntax worked in Odoo 12.
I think Yenthe is correct, it's not the self.env.user.has_group('group'). It's an issue with computed fields.
If the computed field is defined as "stored" there is no error. I think that's because it gets run as superuser. But it also doesn't work if it is stored.
Same issue found of ks_chart_data field computation in upgrading ks_dashboard_ninja addon 12.0.8.0.0 to compatible with odoo 13.0