简体   繁体   中英

How to make an existing button invisible only for specific group. Odoo 14

I want to make the button 'Reset To Draft' in model 'account.move' visible only for 'account.group_account_invoice' that means, it should be invisible for group 'account.group_account_manager' , here is my code;

   <record id="account_move_form_view_extend" model="ir.ui.view">
            <field name="name">account.move.form.view.extend</field>
            <field name="model">account.move</field>
            <field name="inherit_id" ref="account.view_move_form"/>
            <field name="arch" type="xml">
             <xpath expr="//header//button[@name='button_draft']" position="attributes"/>
                <attribute name="groups">account.group_account_manager</attribute><xpath/>
                <attribute  name ="attrs=">{'invisible' : [('show_reset_to_draft_button', '=', True)]}</attribute>
            </field>
        </record>

But I got this error:

 raise ValueError(formatted_message).with_traceback(from_traceback) from from_exception
odoo.exceptions.ValidationError: Error while validating view:

Element '<attribute name="groups">' cannot be located in parent view

View name: account.move.form.view.extend

What's wrong please? How can I do it? Thanks.

You have a bad definition of the view. That's how it would be corrected.

<record id="account_move_form_view_extend" model="ir.ui.view">
    <field name="name">account.move.form.view.extend</field>
    <field name="model">account.move</field>
    <field name="inherit_id" ref="account.view_move_form"/>
    <field name="arch" type="xml">
         <xpath expr="//header//button[@name='button_draft']" position="attributes">
            <attribute name="groups">account.group_account_manager</attribute>
            <attribute name="attrs">{'invisible' : [('show_reset_to_draft_button', '=', True)]}</attribute>
         </xpath>
    </field>
</record>

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