简体   繁体   中英

Odoo How to hide edit button based on User Group?

I want to hide edit button based on user group. However I don't want to edit ir.model.access.csv, because some process in my system flow must be able some user group to write the model by code.

Are there some way to hide edit button from some group of user ?

I found the answer by myself. I just add the attribute to inherit view like the following code :

    <record model="ir.ui.view">
        <field name="name">edit_button</field>
        <field name="model">account.move</field>
        <field name="inherit_id" ref="account.view_move_form"/>
        <field name="groups_id" eval="[(4,ref('wongnai_flow.group_edit')),(4, ref('wongnai_flow.group_cs')),(4, ref('wongnai_flow.group_ae')),(4, ref('wongnai_flow.group_csm'))]"/>
        <field name="arch" type="xml">
            <xpath expr="/form" position="attributes">
                <attribute name="create">false</attribute>
                <attribute name="edit">false</attribute>
            </xpath>
        </field>
    </record>

Thanks for your answer, it really helped me.

But when i remove edit/create button for some group (ex: Purchase: User), also the edit/create buttons got removed for the higher groups (ex: Purchase: Manager) of the specified group (ex: Purchase: User).

My case : I've removed edit button for Purhcase: User group, and I see the edit button got removed also for the Purchase: Manager group.

The solution I tried : I have created one more view for Purchase: Manager group and given edit TRUE. So I've created two views for two groups

Looking for better solution to achieve this scenario with single view, as it isn't good to create many views for many groups.

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