KSA | Bahrain | UAE | India

One Click, Multiple Updates: Building Custom Wizards in Odoo 20

Have you ever needed to perform an operation on multiple records without creating a permanent database record? Or wanted to collect a few details from a user before executing a specific business operation?

This is where custom wizards in Odoo 20 become useful. Wizards provide temporary forms that let users enter information, review selections and run an operation without navigating through multiple screens. They are commonly used for bulk updates, data imports, confirmation dialogs, report generation and other workflow operations.

In this guide we build a practical wizard from scratch with Odoo 20’s Python framework and XML views. Our example is a Bulk Course Fee Update Wizard: the user selects several training courses, enters a percentage increase and updates all their fees in one operation. The guide also uses Odoo 20’s new security file, security/ir.access.csv, which replaces the older ir.model.access.csv.

1. Understanding Wizards in Odoo

An Odoo wizard is a temporary model-based form used to collect information and perform an operation. Unlike a regular business model, a wizard is generally not meant to store permanent business data. Its records are stored temporarily and periodically cleaned up by Odoo. Odoo provides the models.TransientModel class for this purpose.

Model types in Odoo

Model type Purpose
models.Model Stores regular, persistent business records
models.TransientModel Stores temporary records that are periodically cleaned
models.AbstractModel Defines reusable model functionality without creating a regular database table

For example, res.partner stores customers and contacts, sale.order stores sales orders, and a custom wizard model can temporarily store the percentage a user wants to apply to selected course fees.

How long does wizard data remain?

Transient records are not deleted immediately after a wizard closes. Odoo cleans them according to its configured limits. In Odoo 20, the cleanup runs at most once every five minutes. The default idle lifetime is commonly one hour, but the effective value is controlled by the transient_age_limit configuration setting, which administrators can change. Do not use a wizard to store information that must be kept permanently.

Important: a TransientModel is subject to the same access control as any other model. In Odoo 20 that control is defined through the unified ir.access model, which replaces the separate access control lists (ir.model.access) and record rules (ir.rule) of Odoo 19 and earlier. A custom wizard therefore needs an access rule of its own (see section 8). The older idea that users can only see their own transient records does not describe Odoo 20 behaviour.

2. Understanding the Example

Imagine a training institute that manages several courses in Odoo and wants to raise the fees of selected courses by a percentage. Updating every course one by one takes time. Instead, a wizard lets the user:

  1. Open the Training Courses list.
  2. Select multiple courses.
  3. Open the Actions control and choose Update Course Fees.
  4. Enter a percentage increase.
  5. Apply the update to all selected courses.

In the screenshots used in this guide, the institute has three courses and raises each fee by 50%:

Course Current fee Increase New fee
AI training ₹33,000.00 50% ₹49,500.00
cloud computing ₹38,500.00 50% ₹57,750.00
Basic computer programming ₹11,000.00 50% ₹16,500.00

The amounts are shown in rupees because the example database uses the Indian rupee as its company currency; the course fee follows the currency of each course. The same approach works for discounts, price adjustments, status changes and other bulk operations.

3. Creating the Custom Module

Create a custom module named training_management with this structure:

training_management/
├── __init__.py
├── __manifest__.py
├── models/
│   ├── __init__.py
│   └── training_course.py
├── wizard/
│   ├── __init__.py
│   └── course_fee_wizard.py
├── security/
│   └── ir.access.csv
├── views/
│   ├── training_course_views.xml
│   └── course_fee_wizard_views.xml
└── tests/
    ├── __init__.py
    └── test_course_fee_wizard.py

The module contains a regular model for courses, a transient model for the wizard, XML views for both, an access-rule file and a test for the wizard’s main operation. Note the security file name: in Odoo 20 it is ir.access.csv, not ir.model.access.csv.

4. Creating the Training Course Model

First, create the regular model that stores course information in models/training_course.py:

from odoo import models, fields


class TrainingCourse(models.Model):
    _name = 'training.course'
    _description = 'Training Course'

    name = fields.Char(
        string='Course Name',
        required=True
    )

    duration = fields.Integer(
        string='Duration (Days)'
    )

    currency_id = fields.Many2one(
        'res.currency',
        string='Currency',
        default=lambda self: self.env.company.currency_id,
        required=True
    )

    fee = fields.Monetary(
        string='Course Fee',
        currency_field='currency_id',
        required=True
    )

    description = fields.Text(
        string='Description'
    )

    active = fields.Boolean(
        default=True
    )

training.course is a regular Odoo model: its records stay in the database until they are archived or deleted. We use fields.Monetary for the fee instead of a plain Float because the value represents money. The currency_id field tells Odoo which currency and rounding rules apply.

Import the model in models/__init__.py:

from . import training_course

And import both packages in the module’s root __init__.py:

from . import models
from . import wizard

5. Creating the Training Course Views

Before configuring the manifest, create the course views that it will load. Create views/training_course_views.xml:

<odoo>

    <record id="view_training_course_list" model="ir.ui.view">
        <field name="name">training.course.list</field>
        <field name="model">training.course</field>
        <field name="arch" type="xml">
            <list string="Training Courses">
                <field name="name"/>
                <field name="duration"/>
                <field name="fee"/>
                <field name="currency_id" optional="hide"/>
                <field name="active"/>
            </list>
        </field>
    </record>

    <record id="view_training_course_form" model="ir.ui.view">
        <field name="name">training.course.form</field>
        <field name="model">training.course</field>
        <field name="arch" type="xml">
            <form string="Training Course">
                <sheet>
                    <group>
                        <field name="name"/>
                        <field name="duration"/>
                        <field name="fee"/>
                        <field name="currency_id"/>
                        <field name="active"/>
                    </group>

                    <group>
                        <field name="description"/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <record id="action_training_courses" model="ir.actions.act_window">
        <field name="name">Training Courses</field>
        <field name="res_model">training.course</field>
        <field name="view_mode">list,form</field>
    </record>

    <menuitem
        id="menu_training_root"
        name="Training Management"
        sequence="10"
    />

    <menuitem
        id="menu_training_courses"
        name="Training Courses"
        parent="menu_training_root"
        action="action_training_courses"
        sequence="10"
    />

</odoo>

This creates the list and form views and adds the menu. Once the module is installed and a few courses are created, Training Management ‣ Training Courses looks like Figure 1: the list shows each course’s name, duration, fee and active status, with the currency column hidden by default. The checkboxes in front of each row let users select several courses before opening the wizard.

Figure 1: The Training Courses list under Training Management, showing three courses with their duration, fee and Active status.

6. Creating the Wizard Using TransientModel

Now create the wizard itself in wizard/course_fee_wizard.py:

from odoo import models, fields, api, _
from odoo.exceptions import UserError, ValidationError


class CourseFeeWizard(models.TransientModel):
    _name = 'training.course.fee.wizard'
    _description = 'Bulk Course Fee Update Wizard'

    course_ids = fields.Many2many(
        'training.course',
        string='Selected Courses',
        readonly=True
    )

    percentage = fields.Float(
        string='Increase Percentage',
        required=True,
        default=10.0
    )

    @api.model
    def default_get(self, fields_list):
        res = super().default_get(fields_list)

        if 'course_ids' in fields_list:
            if self.env.context.get('active_model') == 'training.course':
                active_ids = self.env.context.get('active_ids', [])
                courses = self.env['training.course'].browse(
                    active_ids
                ).exists()

                res['course_ids'] = [
                    fields.Command.set(courses.ids)
                ]

        return res

    @api.constrains('percentage')
    def _check_percentage(self):
        for wizard in self:
            if wizard.percentage <= 0:
                raise ValidationError(
                    _("The increase percentage must be greater than zero.")
                )

    def action_apply(self):
        self.ensure_one()

        if not self.course_ids:
            raise UserError(
                _("Please select at least one training course.")
            )

        if self.percentage <= 0:
            raise UserError(
                _("The increase percentage must be greater than zero.")
            )

        for course in self.course_ids:
            new_fee = course.fee * (
                1 + self.percentage / 100
            )

            course.write({
                'fee': course.currency_id.round(new_fee)
            })

        return {
            'type': 'ir.actions.client',
            'tag': 'display_notification',
            'params': {
                'title': _('Success'),
                'message': _(
                    'Course fees have been updated successfully.'
                ),
                'type': 'success',
                'sticky': False,
                'next': {'type': 'ir.actions.act_window_close'},
            },
        }

Let us go through the important parts.

6.1 Inheriting TransientModel

class CourseFeeWizard(models.TransientModel) tells Odoo that the model is meant for temporary records. The wizard stores the user’s input while the operation runs, and its records are cleaned up later by Odoo’s transient-record vacuum.

6.2 Defining the fields

course_ids is a Many2many field that stores the selected courses; a Many2many is needed because one wizard works on several courses. percentage collects the increase from the user. It is required and starts at 10, which the user can change (the screenshots later use 50).

6.3 Understanding default_get()

The wizard must be filled automatically with the courses selected in the list. Odoo calls default_get() to compute default values for a new record. When an action is launched from a list view, Odoo puts information about the selection in the context:

Context key Purpose
active_model Name of the model from which the action was launched
active_id ID of the active record, when applicable
active_ids IDs of the selected records

The code checks that the action was launched from training.course, reads active_ids, and uses browse(...).exists() to build a recordset that skips records that no longer exist.

fields.Command.set(courses.ids) then replaces the Many2many relation with those records. This is how a wizard can work on records selected in another view.

6.4 Validating the percentage

A wizard should validate user input before it changes business data. The @api.constrains method rejects zero or negative percentages by raising a ValidationError. The message is wrapped in _() so Odoo can translate it for users.

6.5 Applying the fee update

action_apply() is the button method. ensure_one() states that it works on a single wizard record. It checks the selection and the percentage again on the server (never rely only on the form), then calculates each new fee and rounds it with the course’s currency (course.currency_id.round(...)). Financial values should follow the currency’s rounding rules instead of raw floating-point results; for example, 7000 × 1.1 in floating point is 7700.000000000001.

Finally the method returns a display_notification client action. The next entry in params is important: it runs ir.actions.act_window_close after the notification, so the wizard dialog closes and the list behind it reloads with the new fees. Without next, Odoo shows the notification but leaves the dialog open, and a second click on Apply would raise the fees again. Figure 5 later in this guide shows that behaviour.

6.6 Importing the wizard

Inside wizard/__init__.py:

from . import course_fee_wizard

The root __init__.py already imports the wizard package, so Odoo can load the model.

7. Creating the Wizard XML View and Window Action

The Python model defines fields and behaviour; an XML form lets users interact with it. Create views/course_fee_wizard_views.xml:

<odoo>

    <record id="view_course_fee_wizard_form" model="ir.ui.view">
        <field name="name">training.course.fee.wizard.form</field>
        <field name="model">training.course.fee.wizard</field>
        <field name="arch" type="xml">
            <form string="Bulk Course Fee Update">

                <group>
                    <field
                        name="course_ids"
                        widget="many2many_tags"
                        readonly="1"
                        force_save="1"
                    />

                    <field name="percentage"/>
                </group>

                <footer>
                    <button
                        name="action_apply"
                        string="Apply"
                        type="object"
                        class="btn-primary"
                    />

                    <button
                        string="Cancel"
                        special="cancel"
                        class="btn-secondary"
                    />
                </footer>

            </form>
        </field>
    </record>

    <record id="action_course_fee_wizard" model="ir.actions.act_window">
        <field name="name">Update Course Fees</field>
        <field name="res_model">training.course.fee.wizard</field>
        <field name="view_mode">form</field>
        <field name="view_id" ref="view_course_fee_wizard_form"/>
        <field name="target">new</field>

        <field name="binding_model_id" ref="model_training_course"/>
        <field name="binding_view_types">list</field>

        <field name="context">{'default_percentage': 10}</field>
    </record>

</odoo>

Understanding the XML components

  • Form view: the <form> element defines the wizard’s interface.
  • Many2many field: the many2many_tags widget shows the selected courses as tags. The field is read-only because the selection comes from the list. force_save="1" is a safeguard for the read-only field; it does not replace checking that default_get() really supplies the courses.
  • Apply button: type="object" makes Odoo call the Python method action_apply().
  • Cancel button: special="cancel" closes the wizard without running anything and needs no Python method.
  • Window action: target="new" opens the form in a dialog. The dialog title comes from the action’s name, which is why the dialog in the screenshots reads “Update Course Fees” and not the form’s string.

Understanding the contextual action binding

The two fields binding_model_id and binding_view_types bind the action to the list view of the Training Course model, so users can reach it from the Actions control after selecting records. The context shows how to pass a default from XML: keys that start with default_ fill the matching wizard field. Here it repeats the Python default of 10; use it when different actions need different defaults.

8. Configuring Access Rules and the Manifest

8.1 Access rules with ir.access

Odoo 19 and earlier defined model access in security/ir.model.access.csv and record rules in XML (ir.rule). Odoo 20 replaces both with a single model, ir.access, loaded from security/ir.access.csv.

Create security/ir.access.csv:

id,name,model_id,group_id/id,operation,domain
access_training_course_user,training.course user,training.course,base.group_user,crud,
access_course_fee_wizard_user,course fee wizard user,training.course.fee.wizard,base.group_user,crud,

For comparison, this is the old Odoo 19 format that the same two rules would have used. Do not use it in Odoo 20:

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_training_course_user,training.course user,model_training_course,base.group_user,1,1,1,1
access_course_fee_wizard_user,course fee wizard user,model_training_course_fee_wizard,base.group_user,1,1,1,1

The columns of the new file are:

Column Meaning
id External ID of the rule, for example access_training_course_user
name A readable name
model_id The technical model name, such as training.course. It is not the old XML ID model_training_course, and the header has no :id suffix.
group_id/id XML ID of the security group the rule applies to, such as base.group_user
operation The permitted operations as letters: c create, r read, u write (update) and d delete, for example crud or r
domain An optional Python domain that limits which records the rule covers. Leave it empty for no restriction; this is the role the old record rules played.

One behaviour to remember: a row that has a group grants permission to that group, while a row with an empty group_id/id acts as a restriction that applies to everyone, much like a global record rule. Always fill the group on permission rows such as the two above.

The first row gives internal users full rights on training courses and the second lets them create and use wizard records. This is convenient for a demonstration, but a real module should give permissions according to organisational roles, for example read-only rights for most users and full rights for a training manager group. After installing the module you can review the imported rows from the Access Rights list under the Technical menu in developer mode.

8.2 Manifest file

Now configure __manifest__.py. The data file list names security/ir.access.csv:

{
    'name': 'Training Management',
    'version': '1.0',
    'category': 'Education',
    'summary': 'Training Course Management with Custom Wizards',
    'description': """
        Manage training courses and update multiple course fees
        using a custom wizard.
    """,
    'depends': ['base'],
    'data': [
        'security/ir.access.csv',
        'views/training_course_views.xml',
        'views/course_fee_wizard_views.xml',
    ],
    'installable': True,
    'application': True,
    'license': 'LGPL-3',
}

The order matters for the views: the form view must be loaded before the window action that refers to it with view_id. In this example both are in the same file and the form comes first.

9. Testing the Wizard

Install or upgrade the module: restart the server if required, activate developer mode, open Apps, update the Apps list if the module is new, search for Training Management and install it (or upgrade it if it is already installed so that the new files are loaded). Then test the full workflow:

  1. Open Training Management ‣ Training Courses and create a few courses. Figure 1 shows three: AI training (₹33,000), cloud computing (₹38,500) and Basic computer programming (₹11,000).
  2. Select two or more courses with the list checkboxes. Figure 2 shows all three selected: the control panel then displays “3 selected” and the Actions control (highlighted).

    Figure 2: All three courses are selected and the Actions control (highlighted) appears in the control panel.

  3. Open Actions. Beside the standard Export, Duplicate, Archive, Unarchive and Delete entries, Odoo lists our Update Course Fees action (Figure 3), because the window action is bound to this model’s list view.

    Figure 3: The Actions menu with the custom Update Course Fees action (highlighted) below the standard actions.

  4. The wizard opens in a dialog (Figure 4). The three selected courses are already shown as tags, thanks to default_get(). Type the percentage; the field starts at 10, and we enter 50.

    Figure 4: The Update Course Fees wizard with the three selected courses, an Increase Percentage of 50.00 and the Apply button.

  5. Click Apply. The wizard executes action_apply(), updates the three courses and shows a success notification (Figure 5).

    Figure 5: The success notification (highlighted) after clicking Apply. In this capture the dialog is still open and the list behind it still shows the old fees, because the action returned only a notification and no close action.

Figure 5 is a useful illustration of a common pitfall. Because the action in this capture returned only the notification, the dialog stayed open and the list behind it was not refreshed. With the next entry from section 6.5, the dialog closes by itself and the list reloads. Close the dialog (or use the final code from this guide) before checking the result.

  1. Check the list. Figure 6 shows the revised fees in the highlighted column.

    Figure 6: The updated Course Fee column (highlighted) after the 50% increase: ₹49,500.00, ₹57,750.00 and ₹16,500.00.

The results match the calculation from section 2:

Course Original fee Updated fee
AI training ₹33,000.00 ₹49,500.00
cloud computing ₹38,500.00 ₹57,750.00
Basic computer programming ₹11,000.00 ₹16,500.00

Also test as an ordinary internal user, not only as the administrator. The administrator bypasses many checks, so a regular user is the best way to confirm that the ir.access.csv rows give the rights you intended.

9.1 Testing with Odoo’s Form helper

In addition to manual testing, you can use Odoo’s testing framework. The Form helper simulates form interactions and tests default values. Create tests/test_course_fee_wizard.py:

from odoo.tests import TransactionCase, Form


class TestCourseFeeWizard(TransactionCase):

    @classmethod
    def setUpClass(cls):
        super().setUpClass()

        cls.course = cls.env['training.course'].create({
            'name': 'AI training',
            'duration': 60,
            'fee': 33000,
            'currency_id': cls.env.company.currency_id.id,
        })

    def test_course_fee_update_wizard(self):

        Wizard = self.env['training.course.fee.wizard'].with_context(
            active_model='training.course',
            active_ids=self.course.ids,
        )

        with Form(Wizard) as wizard_form:
            wizard_form.percentage = 50

        wizard = wizard_form.save()

        self.assertEqual(wizard.course_ids, self.course)

        wizard.action_apply()

        self.assertEqual(
            self.course.fee,
            self.course.currency_id.round(49500)
        )

The test checks that the wizard receives the selected course from the context, that the percentage can be entered through the form helper, and that Apply updates the fee. Add the import to tests/__init__.py:

from . import test_course_fee_wizard

Run it with Odoo’s test runner with the module and test options enabled. Tests run as the superuser by default, so they do not prove that normal users have the right access.

10. Advanced Wizard Techniques

10.1 Using onchange() for user feedback

The @api.onchange decorator reacts to field changes while the user edits the form. For example, a warning can appear when a negative percentage is typed:

@api.onchange('percentage')
def _onchange_percentage(self):
    if self.percentage < 0:
        return {
            'warning': {
                'title': _('Invalid Percentage'),
                'message': _(
                    'Please enter a positive percentage.'
                ),
            }
        }

An onchange gives immediate feedback but is not validation. Keep the @api.constrains check from section 6 so invalid values can never be saved.

10.2 Populating several fields with default_get()

default_get() can fill several wizard fields from the context, for example a default discount computed from selected sales orders. For a fixed value, a field’s default= argument or a default_ key in the action context (section 7) is simpler. Use default_get() when the value depends on the selected records.

10.3 Creating a multi-step wizard

Some processes need more than one form. A data import wizard might have an upload step followed by a review step. Manage the steps with a state field:

state = fields.Selection(
    [
        ('upload', 'Upload'),
        ('review', 'Review'),
    ],
    default='upload'
)

The XML view shows different sections depending on the state, using the expression syntax of modern Odoo view architectures:

<group invisible="state != 'upload'">
    <field name="file_data"/>
</group>

<group invisible="state != 'review'">
    <field name="preview_data"/>
</group>

To move to the next step, update the state and return an action that reopens the same wizard record:

def action_review(self):
    self.ensure_one()

    self.state = 'review'

    return {
        'type': 'ir.actions.act_window',
        'name': _('Review Import'),
        'res_model': self._name,
        'view_mode': 'form',
        'res_id': self.id,
        'target': 'new',
    }

The res_id tells Odoo to reopen the existing record instead of creating a new one, and target="new" keeps it in a dialog.

10.4 Returning an action to display updated records

Sometimes a notification is not enough and you want to take the user to the records that were just changed. Instead of the notification, action_apply() can return a window action:

return {
    'type': 'ir.actions.act_window',
    'name': _('Updated Training Courses'),
    'res_model': 'training.course',
    'view_mode': 'list,form',
    'domain': [
        ('id', 'in', self.course_ids.ids)
    ],
    'target': 'current',
}

Use the notification (with next) when users only need confirmation, and the window action when they should inspect the updated records straight away.

11. Common Mistakes When Creating Wizards

  1. The wizard does not open. Check the ir.actions.act_window record, its res_model, the referenced view and the target value.
  2. Selected records are not displayed. Verify that the action is bound to the correct model and list view, and check the active_model and active_ids values received in the context.
  3. Access error on the wizard model. Check that the wizard has a row in security/ir.access.csv, that the file is listed in the manifest, and that the user belongs to the group named in group_id/id.
  4. The module fails to install after copying an older tutorial. In Odoo 20, security/ir.model.access.csv and ir.rule records are replaced by security/ir.access.csv. Migrate the file, using the model name in model_id and the single operation column.
  5. Invalid values are accepted. Use server-side validation such as @api.constrains or explicit checks in the operation method. An onchange warning alone does not enforce a rule.
  6. The wizard stays open after Apply. Add next: {type: ir.actions.act_window_close} to the notification, or return another action, so the dialog closes and the list reloads. Otherwise users may click Apply twice.
  7. The wizard opens as a regular page. Check that the window action uses <field name="target">new</field>.
  8. A multi-step wizard starts again from the first step. Make sure the returned action includes the existing wizard record’s res_id.

12. Best Practices for Odoo Wizard Development

  • Use TransientModel for temporary user input, not for permanent business records.
  • Define ir.access rows for the wizard and for the business models it changes, and give permissions per group.
  • Validate important values on the server, not only through onchange methods.
  • Use Odoo’s translation helper _() for messages shown to users.
  • Use the currency’s rounding method when calculating monetary values.
  • Close the dialog or return a follow-up action after the operation completes.
  • Keep the wizard record ID between steps in multi-step wizards.
  • Test selected-record handling, empty selections, invalid input and different users’ permissions.
  • Keep business logic in Python and use XML mainly for the interface.

Conclusion

Custom wizards are a useful part of Odoo development. They provide a structured way to collect user input, process selected records and guide users through operations without creating a permanent record for every interaction.

In this example we built a Bulk Course Fee Update Wizard with models.TransientModel, Python methods, XML form views, a contextual window action and Odoo 20’s ir.access.csv. The same approach fits bulk price updates, confirmation dialogs, data imports, mass status changes and multi-step workflows.

Frequently Asked Questions

1. What is a wizard in Odoo?

A wizard is a temporary form used to collect user input and perform an operation. It is commonly implemented with models.TransientModel.

2. What is the difference between Model and TransientModel?

models.Model is for regular, persistent business records. models.TransientModel is for temporary records that Odoo periodically cleans up.

3. Do custom Odoo wizards need access rights?

Yes. In Odoo 20, access to a TransientModel is controlled like any other model, through ir.access rows in security/ir.access.csv. Define suitable permissions for the wizard.

4. What replaced ir.model.access.csv in Odoo 20?

A single file, security/ir.access.csv, loaded into the unified ir.access model. It also holds what record rules used to define, in its optional domain column.

5. How can a wizard receive selected records from a list view?

A contextual window action passes them through active_model and active_ids. The wizard reads them with self.env.context.

6. Why is target=”new” used in a wizard action?

It opens the wizard in a dialog instead of replacing the current page.

7. Why does my wizard stay open after the notification?

A display_notification action does not close the dialog by itself. Add a next entry with ir.actions.act_window_close.

8. Can an Odoo wizard have multiple steps?

Yes. Use a Selection field for the state, conditional visibility in the XML, and return a window action with res_id to reopen the same wizard record.

9. Are wizard records deleted immediately after closing the popup?

No. They are cleaned up periodically according to Odoo’s configured limits, so they should not be treated as permanent storage.

References

Official documentation

Leave a Reply

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