Smart Button In Odoo
SMART BUTTON IN ODOO
In Odoo Smart buttons allow you to see all the related records in the form view. We can also add a counter to count the number of records present in it. It is very useful to navigate to related documents or data very quickly.
Smart Button’s are special type of button which will be displayed as a rectangle with an icon. This button will have two types.
- object.
- action
If type is object it will call a function, if type is action it will call a record.
<xpath expr="//div[@class='oe_button_box']" position="inside"> <button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive"> </button> </xpath> In practical case:
<?xml version="1.0" encoding="UTF-8" ?> <odoo> <record id="create_wizard_form" model="ir.ui.view"> <field name="name">New Wizard</field> <field name="model">odoo.wizard</field> <field name="arch" type="xml"> <form string="Wizard Details"> <group> <field name="name"/> <field name="dob"/> </group> <xpath expr="//div[@class='oe_button_box']" position="inside"> <button name="toggle_active" type="object" class="oe_stat_button" icon="fa-star" string="Sample"> </button> </xpath> </form> </field> </record> <record id="action_new_wizard" model="ir.actions.act_window"> <field name="name">Sample Wizard</field> <field name="res_model">odoo.wizard</field> <field name="type">ir.actions.act_window</field> <field name="view_mode">form</field> <field name="target">new</field> </record> <menuitem name ="new_wizard_menu" id ="odoo_wizard_id" action="action_new_wizard"/> </odoo> Here you can change button position and icons as your wish The Output will like this:
ADDING SMART BUTTON BY INHERITANCE
Step 1: inherit our sale oder module,
eg: class SaleOrder(models.Model):
_inherit=’sale.order’
Step 2:
add this code in xml bofore field declaration
<xpath expr="//div[@class='oe_button_box']" position="inside"> <button name="toggle_active" type="object" class="oe_stat_button" icon="fa-star" string="Sample"> </button> </xpath> Here you can change the position and string as your wish. Now it shows like this:
To Know more about us