Enable Dark Mode!
By: Vishnuraj P

How to Add Smart Buttons in Odoo 17

Technical Odoo 17

Smart Buttons in Odoo are interactive components strategically placed within records, offering users a quick and contextual means to perform related actions or gain insights without navigating away from the current view. These buttons intelligently aggregate and display relevant information, transforming static data presentation into a dynamic user experience.

In Odoo 17, the smart button comes with a new stylish view, below is the contacts form view with some smart buttons in it. Let's see how to add smart buttons in the Odoo 17 Module.

How to Add Smart Buttons in Odoo 17-cybrosys

This Joel Willis contact form contains Meetings, Tasks, and Invoiced smart buttons. Also, we can see an icon and the related record count from the smart button. Now, we are going to add a new smart button on this form, which will show the assigned vehicle record for this partner from the fleet module.

Adding smart button in the form view

For adding a button along with other smart buttons, we have to inherit the form view and add the button inside a <div> with name “button_box”.

    <record id="view_partner_form" model="ir.ui.view">
        <field name="name">res.partner.form.inherit.my.blog</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_form"/>
        <field name="arch" type="xml">
            <div name="button_box" position="inside">
                <button class="oe_stat_button" 

By adding this record and a function “action_get_vehicles_record” mentioned in the record on res.partner class, you will get a new smart button in partner form with a fa-taxi icon.

How to Add Smart Buttons in Odoo 17-cybrosys

Name and data for the smart button

Now, we can add button names and record counts on this newly added smart button.

For that, inherit res.partner model and add a field and compute function like this.

class ResPartner(models.Model):
    _inherit = "res.partner"
    vehicle_count = fields.Integer(string="Vehicles",
    def compute_vehicle_count(self):
        for record in self:
            record.vehicle_count = self.env['fleet.vehicle'].search_count(
                [('driver_id', '=', self.id)])

Make this data available on the smart button and update your XML record with the vehicle_count field in the button tag.

<div name="button_box" position="inside">
    <button class="oe_stat_button" type="object" icon="fa-taxi"
        <field string="Vehicles" name="vehicle_count" widget="statinfo"/>

Then, you can see the smart button string and vehicle count.

How to Add Smart Buttons in Odoo 17-cybrosys

Define action for smart button

Now, we can define the action for the smart button by updating the “action_get_vehicles_record” function to filter the view of vehicle records assigned to the partner.

    def action_get_vehicles_record(self):
        return {
            'type': 'ir.actions.act_window',
            'name': 'Vehicles',
            'view_mode': 'tree',
            'res_model': 'fleet.vehicle',
            'domain': [('driver_id', '=', self.id)],
            'context': "{'create': False}"

Add some vehicle driver as the current partner in the Fleet module and click the smart button.

How to Add Smart Buttons in Odoo 17-cybrosys

The related vehicles' view results will be as shown in the image below.

How to Add Smart Buttons in Odoo 17-cybrosys

In Odoo 17, Smart Buttons enhance user experience by offering an efficient way to perform actions and access relevant information within record views, optimizing usability and adding a dynamic dimension to data presentation.

If you need any assistance in odoo, we are online, please chat with us.


Leave a comment




Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635



Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.



Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message