İçereği Atla
Menü
Bu soru işaretlendi
3 Cevaplar
5217 Görünümler
I have a field that is readonly if the status field of that model is finished, but if the logged user has a specific group, this field would no longer be readonly, how can I validate the user group in the xml, or some other way to achieve this


Avatar
Vazgeç
En İyi Yanıt

Hi,

This can be achieved using two views, one main view and the other one is inherited view(for which we will set user group).

In the main view, you can set the required field attributes for all users and then create an inherited view and set user group for it, then inside this inherited view, you can change the field properties as per need for this user group.


See an use case here:  Apply Changes In A View For Particular User Groups In Odoo


Thanks

Avatar
Vazgeç

Please notice that this solution cannot be replicated on Odoo 16 or higher

En İyi Yanıt

Hi Pavel,

Try

<field name="comment" attrs="{'readonly': [('state', '!=', 'submit')]}" force_save="1" groups="!base.group_system"/>

<
field name="comment" groups="base.group_system"/>


The "!base.group_system"  in Odoo restricts access to an element, such as a button or field, to all groups except the "Administration/Settings" group.
This means the element will not be accessible by the users who have Administration/Settings access


Hope it Helps,
Kiran K

Avatar
Vazgeç
Üretici En İyi Yanıt
I thought it was working fine for me, but it puts the editable field with any user, even though it doesn't have the group I put in the inherited view
 id="group_maintenance_petitioner" model="res.groups">
name="name">Maintenance Petitioner
name="category_id" ref="module_category_maintenance"/>


id="df_maintenance_work_order_form_inherit" model="ir.ui.view">
name="name">df.maintenance.work.order.form.inherit
name="model">df.maintenance.work.order
name="groups_id" eval="[(4, ref('group_maintenance_petitioner'))]"/>
name="inherit_id" ref="df_maintenance_work_order_form_view"/>
name="arch" type="xml">
name="employee_ids" position="attributes">
name="attrs">{'readonly': ['|',('state', 'in', ('history','cancelled','posted')),('active', '=', False)]}




Avatar
Vazgeç