How To Add Smart
Buttons In Odoo17
Enterprise
Introduction
Enterprise
Smart buttons in Odoo provide quick access to related records
and actions, enhancing the user experience by making
navigation and operations more intuitive and efficient
Enterprise
Step 1 :
● Inherit the desired view and insert button in the smart
button area.
<odoo>
<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"
type="object"
icon="fa-taxi"
name="action_get_vehicles_record">
<field string="Vehicles" name="vehicle_count"
widget="statinfo"/>
</button>
</div>
</field>
</record>
</odoo>
Enterprise
Step 2:
● Add python, inherit the desired model and add function
on the name of the button
from odoo import fields, models
class ResPartner(models.Model):
_inherit = "res.partner"
def action_get_vehicles_record(self):
self.ensure_one()
return {
'type': 'ir.actions.act_window',
'name': 'Vehicles',
'view_mode': 'tree,form',
'res_model': 'fleet.vehicle',
'domain': [('driver_id', '=', self.id)],
'context': "{'create': False}"
}
Enterprise
Step 3
Open the corresponding view where we have added the smart
button, we can see the smart button has been added.
Enterprise
Step 4:
● If we want to see the number of record, We can add an
integer fields and its compute function as in the below
code
vehicle_count = fields.Integer(string="Vehicles",
compute='compute_vehicle_count',
default=0)
def compute_vehicle_count(self):
for record in self:
record.vehicle_count = self.env[
'fleet.vehicle'].search_count(
[('driver_id', '=', self.id)])
Enterprise
Step 5:
Open the view and we can see the count has been added
with the smart button.
For More Info.
Check our company website for related blogs
and Odoo book.
Check our YouTube channel for
functional and technical videos in Odoo.
Enterprise
www.cybrosys.com

How To Add Smart Buttons In Odoo 17 - Odoo Slides

  • 1.
    How To AddSmart Buttons In Odoo17 Enterprise
  • 2.
    Introduction Enterprise Smart buttons inOdoo provide quick access to related records and actions, enhancing the user experience by making navigation and operations more intuitive and efficient
  • 3.
    Enterprise Step 1 : ●Inherit the desired view and insert button in the smart button area. <odoo> <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" type="object" icon="fa-taxi" name="action_get_vehicles_record"> <field string="Vehicles" name="vehicle_count" widget="statinfo"/> </button> </div> </field> </record> </odoo>
  • 4.
    Enterprise Step 2: ● Addpython, inherit the desired model and add function on the name of the button from odoo import fields, models class ResPartner(models.Model): _inherit = "res.partner" def action_get_vehicles_record(self): self.ensure_one() return { 'type': 'ir.actions.act_window', 'name': 'Vehicles', 'view_mode': 'tree,form', 'res_model': 'fleet.vehicle', 'domain': [('driver_id', '=', self.id)], 'context': "{'create': False}" }
  • 5.
    Enterprise Step 3 Open thecorresponding view where we have added the smart button, we can see the smart button has been added.
  • 6.
    Enterprise Step 4: ● Ifwe want to see the number of record, We can add an integer fields and its compute function as in the below code vehicle_count = fields.Integer(string="Vehicles", compute='compute_vehicle_count', default=0) def compute_vehicle_count(self): for record in self: record.vehicle_count = self.env[ 'fleet.vehicle'].search_count( [('driver_id', '=', self.id)])
  • 7.
    Enterprise Step 5: Open theview and we can see the count has been added with the smart button.
  • 8.
    For More Info. Checkour company website for related blogs and Odoo book. Check our YouTube channel for functional and technical videos in Odoo. Enterprise www.cybrosys.com

Editor's Notes

  • #5 Add clear screen shot