Complete Guide to Odoo Form View Buttons: XML, Python, and Actions

TEAM-TRANSINES
April 14, 2026
Illustration showing how to add a button in Odoo18 form view using XML and Python with developers working on a laptop

In Odoo, the ir.ui.view model controls how the records appear on the screen.

When a developer defines a form view, the system will read the XML structure and render a single business record, such as a sales order or employee in the user interface.

When the module installs or updates The form view will be stored in the database, and the server loads it.

Learn how to add, configure, and control buttons in Odoo form views using XML and Python. Understand object and action types, visibility rules, access control, and backend logic with examples.

Where the Button Appears

The <header> section inside a form view is responsible for action controls.

When a developer places a <button> tag inside <header>, the interface displays that button at the top of the form.

That button is not just visual. It can connects directly to server-side logic.

Step 1: Add the Button in XML

The ir.ui.view record will defines the button inside the form structure.

<record id="view_example_form" model="ir.ui.view"> 
 	<field name="name">example.form</field> 
 	<field name="model">example.model</field> 
 	<field name="arch" type="xml"> 
 	 	<form string="Example"> 
 	 	 	<header> 
 	 	 	 	<button name="action_confirm"  	 	 	 	type="object"  	 	 	 	string="Confirm"/> 
 	 	 	</header> 
 	 	 	<sheet> 
 	 	 	 	<group> 
 	 	 	 	 	<field name="name"/> 
 	 	 	 	</group> 
 	 	 	</sheet> 
 	 	</form> 
 	</field> 
</record> 

Here’s what happens:

  • The name attribute points to a Python method.
  • The type=”object” tells the system to call that method on the current record.
  • The interface displays the button with the label Confirm.

Explore our detailed blog on custom menus and actions in Odoo for practical implementation.

Step 2: Define the Backend Method

The models.Model class defines how the record behaves in the database.

from odoo import models, fields

class ExampleModel(models.Model): 
 	_name = 'example.model' 
 	_description = 'Example Model' 
 
 name = fields.Char()  state = fields.Selection([ 
 	 	('draft', 'Draft'), 
 	 	('confirmed', 'Confirmed') 
 	 	], default='draft') 
 
 def action_confirm(self):   for record in self: 
 	 	 	record.state = 'confirmed'

When the user clicks the button:

  1. The interface sends a request to the server.
  2. The ORM executes action_confirm.
  3. The method updates the state field.
  4. The interface refreshes the record.

The result is a visible state change.

Different Button Types

The <button> element supports different behaviors.

Type What It Does Result

object Calls a Python method Updates the current record action Executes ir.actions.act_window Opens another window

The ir.actions.act_window model is used when the button should open a new view instead of updating the current record.

Showing or Hiding the Button

The view engine evaluates conditions defined in the attrs attribute.

<button name="action_confirm" 
        type="object"         string="Confirm"         attrs="{'invisible': [('state', '=', 'confirmed')]}"/> 

When the state field becomes confirmed, the system hides the button.

This prevents duplicate execution.

Restricting Access

The ir.model.access file controls who can execute model methods.

The groups attribute in the button ensures only specific user roles can see or click it.

The security layer validates permissions before running the method.

<button name="action_confirm" 
        type="object"         string="Confirm"         groups="base.group_user"/> 

Connecting with a Status Bar

The form view can display workflow progress using the statusbar widget.

<field name=”state” widget=”statusbar” statusbar_visible=”draft,confirmed”/>

When action_confirm updates the state, the status bar reflects the new stage.

How It All Works Together

  • The ir.ui.view model defines the form layout.
  • The <button> element creates the action trigger.
  • The models.Model class defines the backend logic.
  • The ORM updates the database.
  • The interface reflects the result.

Adding a button in Odoo is therefore a structured process: define it in XML, connect it in Python, and control visibility and access when required.

For more details and technical assistance feel free to contact us

"Automate Your Business with our Customized Odoo ERP Solutions"

"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"

Get a Free Quote

Leave a Reply

Your email address will not be published. Required fields are marked *