Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

3

Make field readonly based on group

By
dirtyHandsPHP
on 7/31/14, 3:27 AM 7,766 views

In Attendance section there is 'name' field used to display/edit date. I am having two user groups 'base.group_user' and 'base.group_hr_user'. I want to use inheritance and make this field readonly for 'base.group_user' group and other group 'base.group_hr_user' should work as it is.

Searched over this community and did some changes like that

<record id="odoo_hr_attendance_view_form" model="ir.ui.view">
            <field name="name">hr.attendance.form.inherit</field>
            <field name="model">hr.attendance</field>
            <field name="inherit_id" ref="hr_attendance.view_attendance_form" />
            <field name="groups_id" eval="[(6,0, [ref('base.group_user')])]" />
            <field name="arch" type="xml">                
                <field name="name" position="attributes">
                   <attribute name="attrs">{'readonly':1}</attribute>                   
                </field>                
            </field>
</record>   

But now it's showing readonly for both the groups.

Can anyone please guide me how to achieve my results?

2
Mariusz Mizgier
On 7/31/14, 6:55 AM

It is because user, which is in base.group_hr_user is also in base.group_user - you should consider adding another attribute, that readonly is 0 when user belongs to base.group_hr_user.

@Mariusz Thanks for your answer. Tried following code as well but still not working : hr.attendance.form.inherithr.attendance{'readonly':1}hr.attendance.form.inherithr.attendance{'readonly':0}

dirtyHandsPHP
on 8/1/14, 1:30 AM

Tried as per your suggestion by adding one more code block with group base.group_hr_user and readonly 1 but not working :(

dirtyHandsPHP
on 8/1/14, 1:32 AM

Sorry readonly 0

dirtyHandsPHP
on 8/1/14, 1:32 AM

Try modyfing definition of name field straight in your py file, like so: 'name': fields.char('Name', size=256, required=True, read=['base.group_user'] ), That should work.

Currenda Sp. z o.o., Mariusz Mizgier
on 8/1/14, 3:16 AM

Thanks but not working this one either :(

dirtyHandsPHP
on 8/1/14, 5:46 AM
4
dirtyHandsPHP
On 8/1/14, 7:32 AM

Thanks @Mariusz. I was able to fix the issue as  per your suggestion with following code:

<record id="oodo_hr_attendance_view_form" model="ir.ui.view">
            <field name="name">hr.attendance.form.inherit</field>
            <field name="model">hr.attendance</field>
            <field name="inherit_id" ref="hr_attendance.view_attendance_form" />
            <field name="groups_id" eval="[(6, 0, [ref('base.group_hr_manager') ])]" />                
            <field name="arch" type="xml">                                   
                <field name="name" position="attributes">
                   <attribute name="readonly">0</attribute>                   
                </field>                             
            </field>
</record>
<r
ecord id="ids_hr_attendance_view_form_mgr" model="ir.ui.view">
            <field name="name">hr.attendance.form.inheritmgr</field>

            <field name="model">hr.attendance</field>
            <field name="inherit_id" ref="hr_attendance.view_attendance_form" />
            <field name="groups_id" eval="[(6, 0, [ref('base.group_user') ])]" />                
            <field name="arch" type="xml">                                   
                <field name="name" position="attributes">
                   <attribute name="readonly">1</attribute>                   
                </field>                              
            </field>
</record>    

0
Mayank Gosai
On 10/14/15, 4:10 AM

Hello Nagarjuna,

Your code is :

<field name="is_reserve_accepted" position="attributes">

<attribute name="attrs">{'readonly':1}</attribute>

</field>

Replace it with:

<field name="is_reserve_accepted" position="attributes">

<attribute name="readonly">1</attribute>

</field>

Hope, it helps you.

0
nagarjuna
On 9/9/15, 7:15 AM

Hi Shiv modi,

i have a view as like below, but the field is still readable. can you please help me on this.

<record id="view_staff_reservation_form" model="ir.ui.view">

<field name="name">reservation.form.view</field>

<field name="model">reservations.reservation</field>

<field name="groups_id" eval="[(6,0, [ref('base.group_library_user')])]" />

<field name="arch" type="xml">

<tree string="Reservation">

<field name="id"></field>

<field name="reserve_item_id"></field>

<field name="from_date"></field>

<field name="to_date"></field>

<field name="is_reserve"></field>

<field name="is_reserve_accepted" position="attributes">

<attribute name="attrs">{'readonly':1}</attribute>

</field>

</tree>

</field>

</record>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 7/31/14, 3:27 AM
Seen: 7766 times
Last updated: 2/23/16, 5:55 AM