I am adding a new button inside the button_box
div of products. To do that I wrote the following code:
<record id="product_template_form_view" model="ir.ui.view">
<field name="name">product.template.common.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button class="oe_stat_button" type="object" name="open_maintenance_equipments" groups="maintenance.group_equipment_manager" icon="fa-wrench">
<field string="Maintenance Equipments" name="maintenance_equipment_count" widget="statinfo"/>
</button>
</div>
</field>
</record>
It works OK, but the button appears on the left side, before the Odoo main buttons of sale, purchase, etc. I would change the code to:
<record id="product_template_form_view" model="ir.ui.view">
<field name="name">product.template.common.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']/button[last()]" position="after">
<button class="oe_stat_button" type="object" name="open_maintenance_equipments" groups="maintenance.group_equipment_manager" icon="fa-wrench">
<field string="Maintenance Equipments" name="maintenance_equipment_count" widget="statinfo"/>
</button>
</xpath>
</field>
</record>
But the problem here would be that in the source view product.product_template_form_view
there is still no button inside the div. So to apply this I should inherit from one of the main views which modify this product view (like the ones introduced by sale, purchase, etc apps). But I do not want to do so, because:
- My module should depend on apps which are not related to my module. I cannot automatically install for example
purchase
when installing my module. - Despite doing this, it won't guarantee the fact that my button is after these "main" buttons, because it will depend on the module installation order.
So, do you know a way to achieve my purpose, like a sequence
field or something like that?