In this blog, we’re going to walk you through how to create your first button action in Odoo 19 from scratch. This tutorial is based on the accompanying Odooistic YouTube video and includes all the essential steps — from setting up the module structure to writing backend code and adding the button in the UI.
Adding a button that triggers a customized action is one of the first steps in Odoo development. Whether you’re building your own module or enhancing an existing one, this guide will help you do it the right way.
📌 What You’ll Build
By the end of this tutorial, you will have created:
✔️ A custom module called demo_button
✔️ A Python model with business logic
✔️ XML view that includes a button
✔️ A server action triggered by clicking the button YouTube
🛠 Step-by-Step Guide
🔹 1. Create Odoo Module Skeleton
Start by defining the structure of your custom module:
demo_button/ ├── __init__.py ├── __manifest__.py ├── models/ │ └── demo_button.py └── views/ └── demo_button_views.xml
Your __manifest__.py should include basic metadata such as name, version, dependencies, and data files.
🔹 2. Define the Model
In models/demo_button.py, add a class that extends models.Model. This is where you define the action method that runs when the button is pressed.
from odoo import models, fields class DemoButton(models.Model): _name = 'demo.button' _description = 'Demo Button Model' def button_action(self): # Logic to execute when button is clicked return True
This method will be linked to the button in the view.
🔹 3. Create the XML View
In views/demo_button_views.xml, define a form view for your model. Add a button element inside the form:
<record id="view_demo_button_form" model="ir.ui.view"> <field name="name">demo.button.form</field> <field name="model">demo.button</field> <field name="arch" type="xml"> <form string="Demo Button"> <header> <button name="button_action" string="Click Me" type="object" class="btn-primary"/> </header> <sheet> <group> <field name="name"/> </group> </sheet> </form> </field> </record>
Here, the button_action is linked to the Python method you created earlier.
🔹 4. Set Access Rights
Don’t forget to add appropriate access control:
access_demo_button_user.xml
Include basic rules for users to access and click the button.
🧠 Tips & Best Practices
✔ Always restart Odoo server after adding new modules.
✔ Check logs for errors — missing fields or wrong XML paths are common issues.
✔ Use descriptive names for button labels and model descriptions. YouTube
📌 Conclusion
This simple but practical tutorial showed you how to add a button in Odoo 19 that executes a custom action. Button actions are fundamental in Odoo module development and can be used for flows like state changes, triggering reports, or integrating external services. YouTube
🎯 Next, you might want to explore how to add wizard popups or server actions with Python logic — topics we’ll cover in future posts!