pythonxmlodooodoo-16

How I can add button to the variants tab in the products screen in Odoo


I try to add a button in the products screen but I can't find the correct path, and I do not know the problem.

this is my code

        <xpath expr="//page[@name='variants']" position="inside">
            <button string="Custom Button" type="object" name="custom_button_method"/>
        </xpath>

==========================================

but it gives an error

Element '<xpath expr="//page[@name=&#39;variants&#39;]">' cannot be located in parent view

Can anyone help me?


Solution

  • Inherit from the view that adds the variant page to force Odoo to resolve the parent view before applying the xpath.

    Example:

    <record id="product_template_form_extend" model="ir.ui.view">
        <field name="name">product.template.form.extend</field>
        <field name="model">product.template</field>
        <field name="inherit_id" ref="product.product_template_only_form_view"/>
        <field name="arch" type="xml">
            <xpath expr="//page[@name='variants']" position="inside">
                <button string="Custom Button" type="object" name="custom_button_method"/>
            </xpath>
        </field>
    </record>