Search code examples
xmlodooodoo-10odoo-view

Not able to add the group sale_manger to action_invoice_cancel button


I want to add sale_manager group to the action_invoice_cancel (Invoice Cancel) button in the customer invoice . My aim is to see that button only for the users in the sale_manager. I tried like this :

Code

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="orchid_invoice_cancel_request_inherit" model="ir.ui.view">
        <field name="name">invoice_cancel_request</field>
        <field name="model">account.invoice</field>
        <field name="inherit_id" ref="account.invoice_form"/>
        <field name="arch" type="xml">
             <button name="action_invoice_cancel" position="after">
                <button string="Cancel Request" type="object" name="cancel_request" attrs="{'invisible':[('state','not in',('open','paid'))]}"/>
             </button>
             <field name = "move_id" position="after">
                <field name = "od_cancel_reason" />
             </field>

             <button name="action_invoice_cancel" position="replace">
                <button name="action_invoice_cancel" type="object" states="draft,proforma2,open" string="Cancel Invoice" groups="base.group_no_one,sales_team.group_sale_manager"/>
             </button>

        </field>
    </record>
</odoo>

But its not working. What to do ? Thanks in advance.


Solution

  • The invoice form's Cancel Invoice button can certainly be modified (replaced or updated via attributes). Based on your question, it seems most likely that your module either does not load your view or maybe you did not re-upgrade your module.

    As for your approach, I will show how to use attributes to change the groups of that button without needing to replace it entirely (as @Cherif suggested).

    This will update one "attribute" of an existing element without needing to redefine the entire element. You should be able to change any one (or more) of the attributes for an element, however we just want to change groups in your case.

    <?xml version="1.0" encoding="utf-8"?>
    <odoo>
        <record id="orchid_invoice_cancel_request_inherit" model="ir.ui.view">
            <field name="name">invoice_cancel_request</field>
            <field name="model">account.invoice</field>
            <field name="inherit_id" ref="account.invoice_form"/>
            <field name="arch" type="xml">
                 <button name="action_invoice_cancel" position="attributes">
                    <attribute name="groups">sales_team.group_sale_manager"</attribute>
                 </button>
            </field>
        </record>
    </odoo>
    

    Views Documentation