Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make field readonly based on group and status?

Tags:

odoo

odoo-8

I want to make field readonly based on group, and status. Like I have two groups:

  1. Manager Group
  2. User Group

If I give User Group to any user and then change Status to Done, then field will be readonly for this user.

Hope I was able to make it clear to understand. Thanks.

like image 382
user1576199 Avatar asked Sep 20 '13 09:09

user1576199


People also ask

How can we make field readonly based on group and status?

First create your form view. Then inherit the view also specify the groups. for example in sale order form view, i want to make the customer reference field readonly for group user when state is not in draft or sent.

How do I make field read only in edit mode?

Try this: <field name="branch_id" attrs="{'readonly': [('id', '>', 0)]}" required="1"/>. You need to first define the id field (it's an integer field) and put it in the view.


2 Answers

Create a functional field of type boolean. If the logged in user is under user group and state is done, then return true. Then in the view, specify attrs="{'readonly':[('boolean_field_name','=',True)]}"

OR

First create your form view. Then inherit the view also specify the groups. for example in sale order form view, i want to make the customer reference field readonly for group user when state is not in draft or sent.

<record id="view_order_form_cust_ref_readonly" model="ir.ui.view">
    <field name="name">sale.order.form.readonly.cust</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="groups_id" eval="[(6, 0, [ref('base.group_user') ])]"/>
    <field name="arch" type="xml">
        <field name='client_order_ref'" position="attributes">
            <attribute name="attrs">{'readonly':[('state','not in',['draft','sent'])]}</attribute>
        </field>
    </field>
</record>
like image 156
OmaL Avatar answered Oct 17 '22 19:10

OmaL


you can apply access rule on field level in OpenERP, like in py

'name': fields.char('Name', size=128, required=True, select=True,
 read=['base.group_user'] ),

And for status in xml:

<field name="name " attrs="{'readonly': [('state','=','done')]}"/>
like image 4
Heroic Avatar answered Oct 17 '22 21:10

Heroic