Tutorial: Creating Smart Buttons
Learn how to create custom smart buttons in Odoo
Smart Button
Stat Info
Tutorial
Overview
This tutorial module teaches you how to create smart buttons in Odoo. Smart buttons are the rectangular stat buttons that appear in the top-right of form views, showing counts and opening related records.
What You'll Learn
- Creating computed fields for button counts
- Performance optimization using search_count() and read_group()
- Button action methods returning window actions
- XML button definition with statinfo widget
- Domain filtering for related records
Contains
- New smart button on Countries showing contact count
- Clickable button that opens filtered contacts
- Action to open contacts for specific country
- Documented Python and XML code
Key Code Example
XML Button Definition
<button name="action_view_contacts"
type="object" class="oe_stat_button" icon="fa-users">
<field name="contact_count" widget="statinfo"/>
</button>
Python Action Method
def action_view_contacts(self):
return {
'type': 'ir.actions.act_window',
'res_model': 'res.partner',
'domain': [('country_id', '=', self.id)],
}
Technical Information
Tutorial: Creating Smart Buttons
Learn how to create custom smart buttons in Odoo
Smart Button
Stat Info
Tutorial
Overview
This tutorial module teaches you how to create smart buttons in Odoo. Smart buttons are the rectangular stat buttons that appear in the top-right of form views, showing counts and opening related records.
What You'll Learn
- Creating computed fields for button counts
- Performance optimization using search_count() and read_group()
- Button action methods returning window actions
- XML button definition with statinfo widget
- Domain filtering for related records
Contains
- New smart button on Countries showing contact count
- Clickable button that opens filtered contacts
- Action to open contacts for specific country
- Documented Python and XML code
Key Code Example
XML Button Definition
<button name="action_view_contacts"
type="object" class="oe_stat_button" icon="fa-users">
<field name="contact_count" widget="statinfo"/>
</button>
Python Action Method
def action_view_contacts(self):
return {
'type': 'ir.actions.act_window',
'res_model': 'res.partner',
'domain': [('country_id', '=', self.id)],
}
Technical Information
Version: 19.0.1.0.0
Dependencies: base, contacts
License: OPL-1
Please log in to comment on this module