Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
9424 Представления

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

Лучший ответ

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.


Аватар
Отменить
Автор

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

Related Posts Ответы Просмотры Активность
1
сент. 21
5722
1
июн. 25
15293
3
апр. 25
5416
0
окт. 24
1223
0
авг. 24
1211