Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
6462 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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.

Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 2 24
2717
0
thg 2 24
10
1
thg 3 15
4889
1
thg 3 25
1250
0
thg 11 24
972