odooodoo-9odoo-view

Hide "Confirm Sale" button in Sale Order form view in Odoo 9


I'm using Odoo 9 community version.

In Sale order form has following buttons:

<button name="action_confirm" states="sent" string="Confirm Sale" class="btn-primary" type="object" context="{'show_sale': True}"/>
<button name="action_confirm" states="draft" string="Confirm Sale" type="object" context="{'show_sale': True}"/>

I'm trying to hide both button from the view. So I have tried with following code.

<record model="ir.ui.view" id="hide_so_confirm_button_form">
    <field name="name">hide.so.confirm.button.form</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">
        <button name="action_confirm" position="attributes">
            <attribute name="invisible">1</attribute>
        </button>
    </field>
</record>

I have also tried following attribute:

<attribute name="states"></attribute>

With above code, it's only hide/affect first button.

Question:

How to hide both Confirm Sale button?


Solution

  • The mechanism without xpath only influences the first hit. That's why you have to use xpath here.

    Another good example (maybe not for Odoo 9 anymore) is setting a new sale.order.line field behind the name field on sale.order form view. The form view is something like this:

    <form>
        <field name="name" /> <!-- sale.order name field -->
        <!-- other fields -->
        <field name="order_line">
            <form> <!-- embedded sale.order.line form view -->
                <field name="name" />
                <!-- other fields -->
            </form>
            <tree> <!-- embedded sale.order.line tree view -->
                <field name="name" />
                <!-- other fields -->
            </tree>
        </field>
    <form>
    

    Using your way could try setting the new field behind sale.order name field (in this example). Using xpath will lead to the goal.

    <xpath expr="//form//tree//field[@name='name']" position="after">
        <field name="new_field" />
    </xpath>
    <xpath expr="//form//form//field[@name='name']" position="after">
        <field name="new_field" />
    </xpath>
    

    So to answer your question directly (EDIT):

    <xpath expr="//button[@name='action_confirm' and @states='sent']" position="attributes">
        <attribute name="states" /> <!-- delete states attribute, it's influencing invisible behaviour -->
        <attribute name="invisible">1</attribute>
    </xpath
    <xpath expr="//button[@name='action_confirm' and @states='draft']" position="attributes">
        <attribute name="states" /> <!-- delete states attribute, it's influencing invisible behaviour -->
        <attribute name="invisible">1</attribute>
    </xpath