Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
9418 Visualizzazioni

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

Avatar
Abbandona

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?

Autore

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

Autore

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

Autore

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

Risposta migliore

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.


Avatar
Abbandona
Autore

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

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

Post correlati Risposte Visualizzazioni Attività
1
set 21
5715
1
giu 25
15281
3
apr 25
5406
0
ott 24
1222
0
ago 24
1208