Search code examples
xpathodooodoo-12

How can I replace the second button with same name using xpath in Odoo


There two buttons in sale order form in with same name

 <button name="action_confirm" id="action_confirm"
                    string="Confirm" class="btn-primary" type="object"
                    attrs="{'invisible': [('state', 'not in', ['sent'])]}"/>
 **<button name="action_confirm"
                   string="Confirm" type="object"
                   attrs="{'invisible': [('state', 'not in', ['draft'])]}"/>**

Need to select second button using xpath and change its attributes


Solution

  • Here try this:

            <!-- make priority bigger to make sure that this XPATH is used after the one
                 that adds the button -->
            <field eval="100" name="priority"/>
            <field name="arch" type="xml">
                <xpath expr='//buttion[@name="action_confirm"][2]' position='replace'/>
            </field>