Guide to Creating a Custom Button in an Odoo19 Form View
Buttons in the Odoo19 form views help the user interface to trigger logic defined in the server-side model. In the Odoo ORM framework, a button typically executes a Python method that modifies a record, opens another view, or triggers a system action.
In the Odoo form view architecture, the ir.ui.view model meant to defines the interface, while a Python model method defines the business logic. When a user clicks a button, the Odoo framework executes the corresponding method on the active record.
What Happens When a Button is Clicked in Odoo
In the Odoo server framework, button execution follows a defined sequence.
- The form view (ir.ui.view) sends the method name to the server.
- The Odoo ORM identifies the method inside the model class.
- The Python method executes within the current recordset.
- The system updates records, opens a wizard, or triggers an action.
This mechanism connects the user interface to server-side business logic.
Step 1: Define the Logic in the Python Model
In the Odoo development, business operations are defined inside a model class derived from models.Model.
In this example, a lease management record contains a state field. A method changes the state from draft to confirmed.
from odoo import models, fields
class RealEstateLease(models.Model):
_name = "realestate.management.lease"
_description = "Lease"
name = fields.Char(string="Lease Reference")
state = fields.Selection([
('draft', 'Draft'),
('confirmed', 'Confirmed'),
], default='draft')
def action_confirm(self):
for record in self:
record.state = 'confirmed'
Step 2: Connect the Button in the Form View (XML)
The Odoo view system (ir.ui.view) defines interface elements using XML.
A button is placed inside the form header to trigger the method.
<record id="view_lease_form" model="ir.ui.view">
<field name="name">lease.form</field>
<field name="model">realestate.management.lease</field>
<field name="arch" type="xml">
<form string="Lease">
<header>
<button name="action_confirm"
type="object"
string="Confirm"
class="btn-primary"
states="draft"/>
</header>
<sheet>
<group>
<field name="name"/>
<field name="state"/>
</group>
</sheet>
</form>
</field>
</record>
Deploying the Button
After defining the model and XML view, the Odoo server must reload the module.
Typical steps include:
- Restart the Odoo server service.
- Upgrade the custom module from the Odoo Apps menu or via command line.
- Open the form view in the Odoo web client.
The form view will display the button when the record state equals draft.
Two Types of Buttons in Odoo
The Odoo framework supports two main button mechanisms.
1. Object Button
An object button directly executes a Python method in the current model.
<button name="method_name"
type="object"
string="Execute"/>
Typical Usage
The model method performs operations such as:
- Changing workflow states
- Validating records
- Triggering calculations
- Opening wizards
The Odoo ORM executes the method on the active recordset.
for more details and technical assistnace feel free to contact us. and stay tuned for more blogs
2. Action Button
An action button triggers a predefined action defined in the Odoo database.
<button name="%(action_external_id)d"
type="action"
string="Open View"/>
The ir.actions.act_window model or other action types control what happens next.
Common actions include:
- Opening a another list view
- Loading a report
- Executing a server action
Example: Opening a Wizard from a Button
In the Odoo workflow design, some actions require user input before the system updates records. and wizards provide this intermediate step.
A Python method can return an action dictionary that opens a wizard.
def action_cancel(self):
self.ensure_one()
return {
'type': 'ir.actions.act_window',
'name': 'Cancel Lease',
'res_model': 'lease.cancel.wizard',
'view_mode': 'form',
'target': 'new',
'context': {'default_lease_id': self.id},
}
This mechanism allows the system to capture additional information before applying changes.
Controlling Button Visibility
The Odoo view engine allows conditional display of buttons using the attrs attribute.
<button name="action_confirm"
type="object"
string="Confirm"
attrs="{'invisible': [('state', '!=', 'draft')]}"/>
Behavior
The Odoo domain evaluator checks the record state.
In the Odoo form view logic, the visibility of the button depends on the value stored in the state field of the record.
If the state is draft, the button appears in the form interface and the user can click it.
If the state is not draft, the Odoo view engine hides the button from the interface.
In the Odoo development framework, a button connects the user interface with server-side business logic.
The process involves three components:
A Python model method that defines the operation.
An XML form view (ir.ui.view) that declares the button.
Odoo ORM that executes the method when the button is clicked.
This structure ensures the interface actions were remain consistent with data model and workflow logic defined in the system. so that is all about creating a Button in a Form in Odoo19 and its a wrap here.
Need More Odoo Development Guides?
Understanding how buttons work in the Odoo framework is just one part of building powerful business workflows. Developers usually combine form buttons with automation, server actions, wizards, and module customization to streamline real-world ERP operations.
If you want to explore more technical tutorials, implementation insights, and practical ERP development guides, visit our blog page.
"Automate Your Business with our Customized Odoo ERP Solutions"
"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"
Get a Free Quote



