Help

0

Odoo 13 - Computed Fields - ORM changes?

Avatar
Chris TRINGHAM

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).

5 Comments
Avatar
Discard

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?

Avatar
Chris TRINGHAM
-

Hi Yenthe

Quite possibly, but I don't know because the error message gives me no information! How can I check?

Avatar
Hilar AK
-

Here the record is an object and you are trying to get a value like dict syntax. Try to access record.field_name

Avatar
Chris TRINGHAM
-

Has this changed in Odoo 13? The same syntax worked in Odoo 12.

Avatar
Chris TRINGHAM
-

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.

2 Answers
2
Avatar
Kanakinfosystems
Best Answer

Hi Chris,

Check this out.

for record in self:

record['x_studio_authorization1'] = False
if self.env.user.has_group('<UserAccessGroup>'):
record['x_studio_authorization1'] = True

Thanks.


2 Comments
Avatar
Discard
Avatar
Chris TRINGHAM
-

Excellent! It works. I don't know why, but it works!!

Avatar
Simon Demming
-

My impression with the computed fields is, that the default values are not properly set. When one uses the default attribute on the field, but has a path without setting the value in the computing method, it fails to set the field to the default value...

0
Avatar
Henry Zhou
Best Answer

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

Avatar
Discard