تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
5229 أدوات العرض
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


الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال

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

أفضل إجابة

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

الصورة الرمزية
إهمال
الكاتب أفضل إجابة
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)]}




الصورة الرمزية
إهمال