简体   繁体   中英

How to make a field readonly for a particular group in Open Erp 7?

I have a field which i want to make it readonly for all the user from a group, lets say base.group_userA. any other users will be able to edit and save the field. How do i do that in openerp?. I have already set all CRUD access rights for all users.

'WO_NOTES' : fields.text("Description"), 

in xml

<field name="WO_NOTES"/>

I had the same problem, only I wanted to show fields only to users in a group. I solved this by inheriting the view and made changes to the specific group.

In your case it should look something like this:

<?xml version="1.0"?>
<openerp>
    <data>
<record model="ir.ui.view"  id="view_id">
    <field name="name">view.id</field>
    <field name="model">your.model</field>
    <field name="inherit_id" ref="id_of_inherited_view"/>
    <field name="groups_id" eval="[(6, 0, [ref('base.group_userA') ])]"/>
    <field name="arch" type="xml">
        <field name="WO_NOTES" position="attributes">
            <attribute name="readonly">1</attribute>
        </field>
    </field>
</record>
    </data>
</openerp>

Hope this helps!

--- A little edit to clarify a little my answer ---

I assume that you have your form view, working fine to all users (with the WO_NOTES editable to all users). With this inheritance, the change will take place only to users belonging to base.group_userA , changing it's attribute to readonly (only to this field and only to users from this group).

The <field name="WO_NOTES" position="attributes"> <attribute name="readonly">1</attribute></field> part will locate the field in the parent view and make it readonly. The <field name="groups_id" eval="[(6, 0, [ref('base.group_userA') ])]"/> limits this change to the specified group.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM