+91 9818211679, +91 9998040067       [email protected]

How To Create Smart Button In Odoo

When creating smart buttons in Odoo you must tie together several aspects of Odoo development. Below are the basic steps to creating a smart button with example code segments.

1. Add required fields to the model so you can store your field.

Odoo CMS - a big picture

2. Create a form view and tree view and create action of form view.

Odoo CMS - a big picture
Odoo CMS - a big picture

3. Then after that, your tree view and form view will be like this.

Odoo CMS - a big picture
Odoo CMS - a big picture

4. We’ll have to write a method in py file.

          @api.multi

          def button_employee(self):

          return {

            'name': _('Employee Form'), (This is form view name you can give any name)

            'view_type': 'form', (This is view type means this is form or which type form view)

            'view_mode': 'tree,form', (Here we give view mode which type created view)

            'res_model': 'employee.training', (Here will be model name of form view)

            'type': 'ir.actions.act_window', (This is act window which is predefined)

            'domain': [('trainee_qualification'(this is field name), 'in', [self.id])],(Here we are calling field name with the help of self which is a record rule)

          }

  5. Now we will make a button as well as add button where we want to add this button.

          <div class="oe_button_box">

          <button class="oe_stat_button" name="button_employee" string="Employee Training"  type="object" icon="fa-edit"/>

</div>


In the above code,

          name = (Name of the function to be called, present in the .py file)

          string = (Here, you can provide the name of the button to be printed in the UI)

          icon = (This is icon name means which specifies the icon of your button if you need a custom

icon, you can check it here, "https://docs.huihoo.com/odoo/training/reference-material/odoo-icon-smart-buttons.pdf")

Odoo CMS - a big picture

This button has added in employee form and my button name is employee training you can see given above image when we will click on this button then my employee training form and tree view will be open. which view we have made upside. 

Contact us if you have any query regarding the same or want any Odoo customization, Custom Odoo Module, Odoo Installation Services from Kanakinfosystems. We have a team of Professional Odoo Developers that provide the best support throughout the entire process. You can Email us at - [email protected] or directly call us on +91-9818211679, 011-42143250 for more details.