How to access logged in user's group in a view in Odoo?

927 views Asked by At

I want to show a field read-only for all users of group named Manager (having read and update rights for that model). They must not be able to update a field called 'x_name'.

I am using odoo web client (Gui) and don't have access of xml file. I am only able to use the GUI so please suggest a solution for working this out through GUI.

2

There are 2 answers

2
George Daramouskas On

Go to Settings -> User Interface -> Views and create a view, give it the following contents:

<record id="give_an_id" model="ir.ui.view">
            <field name="name">give_a_name</field>

            <field name="model">your.model</field>
            <field name="inherit_id" ref="module.the_id_of_the_view_that_field_is_on" />
            <field name="groups_id" eval="[(6, 0, [ref('module.the_id_of_the_group_for_which_you_want_the_field_hidden') ])]" />                
            <field name="arch" type="xml">                                   
                <field name="x_name" position="attributes">
                   <attribute name="readonly">1</attribute>                   
                </field>                              
            </field>
</record>

So what happens here is that the above view gets activated only when the user belongs in groups_id more here.

0
Heroic On

You can achieve it by inheriting a view, also you can create a new inherited view from the GUI and add group id for that view. Enable Debug mode.

Go to Settings > Technical > Views > Create new view

Add All the field like which view you want to inherit, view type

Add Group name inside the Access rights

Inside the architecture add :

<field name="your_field_name" position="attributes">
<attribute name="readonly">1</attribute>
</field>