跳至内容
菜单
此问题已终结
2 回复
6269 查看

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

相关帖文 回复 查看 活动
1
2月 24
2508
0
2月 24
10
1
3月 15
4699
1
3月 25
1087
0
11月 24
861