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

Solution 1:

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