When building custom modules in Odoo 19, wizards are one of the most powerful ways to simplify workflows and improve user experience. Wizards are interactive pop-ups that guide users step by step—whether you’re sending a message, processing bulk data, confirming actions, or applying configurations. They streamline complex processes, reduce errors, and make operations more intuitive.
This guide dives deep into wizards, their types, working mechanisms, best practices, and practical examples, providing developers with everything needed to implement them effectively.
What Are Wizards in Odoo?
A wizard in Odoo is a special kind of model designed to perform actions in a guided, interactive way. Unlike standard models, wizard data is temporary and only exists during the process it serves.
Key Characteristics of Wizards:
- Temporary Data: Records are automatically deleted after use.
- Open Access: Users can interact with wizard records while they exist.
- References: Wizards can link to other models via Many2one fields, but standard models generally don’t store references to wizard records.
- Use Cases:Wizards are perfect for one-time actions like confirming operations, applying templates, performing bulk updates, or collecting extra input before executing a task.
Types of Wizards in Odoo 19
Wizards vary depending on the workflow complexity:
- Simple Wizards
- Single-step forms that perform an immediate action.
- Example: Applying a discount to multiple sales orders.
- Multi-Step Wizards
- Guide users through multiple steps using Next and Previous buttons.
- Example: Employee onboarding or multi-stage approvals.
- Dynamic Wizards
- Fields, steps, or behavior change based on user input.
- Example: Extra fields appear when a checkbox is selected.
How Wizards Work
All wizards are built on Transient Models (models.TransientModel). These models are temporary, session-specific, and ideal for short-lived operations. Wizards are typically displayed in form views and triggered by buttons or server actions.
Key Steps in a Wizard Workflow:
- Define the Transient Model – Collect user input using fields.
- Create the Wizard Form View – Display the fields in a pop-up.
- Trigger the Wizard – Use buttons, menus, or server actions.
- Process the Data – Execute the desired action and close the wizard.
Example: Sales Discount Wizard
# -*- coding: utf-8 -*-
from odoo import models, fields
class SalesDiscountWizard(models.TransientModel):
_name = 'sales.discount.wizard'
_description = 'Wizard for Applying Discounts'
discount_percent = fields.Float(string="Discount (%)", required=True)
reason = fields.Char(string="Reason")
Wizard Form View (XML)
<odoo>
<record id="view_sales_discount_wizard_form" model="ir.ui.view">
<field name="name">sales.discount.wizard.form</field>
<field name="model">sales.discount.wizard</field>
<field name="arch" type="xml">
<form string="Apply Discount">
<group>
<field name="discount_percent"/>
<field name="reason"/>
</group>
<footer>
<button string="Apply" type="object" name="action_apply_discount" class="btn-primary"/>
<button string="Cancel" special="cancel"/>
</footer>
</form>
</field>
</record>
</odoo>
Trigger Wizard from Sales Order Form
Python – Action to Open the Wizard
def action_open_discount_wizard(self):
return {
'type': 'ir.actions.act_window',
'name': 'Apply Discount',
'res_model': 'sales.discount.wizard',
'view_mode': 'form',
'target': 'new',
'context': {'active_ids': self.ids},
}
XML – Add Button in the Sales Order Form
<odoo>
<record id="view_order_form_inherit_discount" model="ir.ui.view">
<field name="name">sale.order.form.inherit.discount</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//header" position="inside">
<button name="action_open_discount_wizard"
string="Apply Discount"
type="object"
class="btn-primary"/>
</xpath>
</field>
</record>
</odoo>
This approach allows users to quickly select records, input details, and apply actions without permanently storing unnecessary data.
Benefits of Using Wizards
- Simplified Workflows: Guide users through complex tasks.
- Clean Database: Temporary records reduce clutter.
- Data Validation: Ensure consistent and correct input.
- Efficiency: Automates repetitive actions and saves time.
Best Practices for Wizards
- Always use Transient Models for temporary data.
- Keep forms simple and focused.
- Validate input with @api.onchange or @api.constrains.
- Use context to pass active IDs or default values.
- Avoid permanent references to wizard records.
- Use target="new" in form views to display pop-ups.
Advanced Concepts
- Data Validation in Wizards
- Dynamic updates with @api.onchange.
- Enforce rules with @api.constrains.
- Dynamic Wizards
- Show or hide fields based on user input or workflow context.
- Multi-Step Wizards
- Implement multiple screens using a state field with Next and Previous buttons.
- Wizard Views & Actions
- Use buttons, menus, or server actions (ir.actions.act_window) to trigger wizards.
Explore More on Odoo Wizards
To deepen your understanding and explore advanced implementations, check out these related guides:
These articles will help you move from foundational knowledge to advanced wizard development, including dynamic behaviors, multi-step workflows, and real-world use cases.
Wizards in Odoo 19 are a powerful tool for creating interactive, efficient, and user-friendly workflows. By leveraging transient models, form views, and action methods, developers can simplify complex business operations, ensure data consistency, and keep the database clean.
This pillar blog provides a solid foundation for understanding and implementing wizards, while additional tutorials can guide you through advanced techniques, multi-step processes, dynamic behaviors, and practical real-world applications—helping you fully harness the potential of wizards in your Odoo projects.
To read more about How to Create and Manage Wizard in Odoo 18, refer to our blog How to Create and Manage Wizard in Odoo 18.