Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
6431 Переглядів

This does not work

field name="price_unit" attrs={'readonly': [('groups_id', 'not in', [ref('purchase.group_purchase_manager')])]}

error

Field 'groups_id' used in attrs ({'readonly': [('groups_id', 'not in', [ref('purchase.group_purchase_manager')])]}) must be present in view but is missing.

Аватар
Відмінити
Найкраща відповідь

Hi,

If you are using odoo 15 or below, you can achieve this by creating a inherited view for this user group and setting readonly for the field from that view.

* Create new inherited view
* assign user group for the view
* xpath the field and make it readonly

Doing this, field will get readonly for the users in this group.

For more, see:  https://www.youtube.com/watch?v=Fsp6lAPHz08


Thanks

Аватар
Відмінити
Автор

Hi. This solution no longer works for V17. I get this error

Inherited view cannot have 'Groups' define on the record. Use 'groups' attributes inside the view definition

Any Ideas? Thanks.

Автор

I was able to figure it out. For anyone in my situation, I achieved this in odoo17 by first creating a new user group that inherited from existing user that can edit the field and created a new view like this.

<xpath expr="//sheet/notebook/page/field[2]/tree/field[@name='price_unit']" position="attributes">
<attribute name="groups">purchase.group_purchase_user</attribute>
</xpath>

<xpath expr="//sheet/notebook/page/field[2]/tree/field[@name='price_unit']" position="after">
<field name="price_unit"
readonly="1"
groups="new_module.new_group,!purchase.group_purchase_user"/>
</xpath>

Notice that I now have 2 price_unit fields.

I believe this works because since the new group inherits the existing group, we have to explicitly specify that the inherited group is not allowed to view this new price_unit field. Hence, !purchase.group_purchase_user

Related Posts Відповіді Переглядів Дія
1
лют. 24
2696
0
лют. 24
10
1
бер. 15
4858
1
бер. 25
1220
0
лист. 24
957