Blogs

Creating Wizard in Odoo

Odoo provides various ways a user can interact via a dynamic form. In Odoo basic modules we have seen a dialogue box appears asking for confirmation that is basically called a wizard. These are transient models as they don’t persist for a long time.

For example, after creating a sales order, the product will be ready for delivery. So we have to click on the validate button to proceed. When we will click on validate button, a dialogue box appears, as below-

Creating Wizard in Odoo

Here we can see a dialogue box asking to write the quantity of product. When we click to apply it automatically makes the done quantity as same as that of demanded quantities. And there are various actions defined behind the button.

Another example is in CRM, when an opportunity is lost, a dialogue box appears, where we have to write the reason.

Creating Wizard in Odoo

Now let us see how we can create a wizard in our custom module. Here we are having a custom student onboard model and the onboard process is carrying on,

Creating Wizard in Odoo

After filling the form and clicking on Confirm button, the state changes from draft to in progress as provided in its function.

Creating Wizard in Odoo

Now when we click on verify, we get the following pop-up,

Creating Wizard in Odoo

Fill out this and click confirm button,

Creating Wizard in Odoo

So let us see how we have defined this wizard model, its corresponding xml file and action. First we have to create a directory ‘wizards’. This has to be imported in __init__.py file. Defined a model for our wizard as follows,

Creating Wizard in Odoo

Wizard is a model generated from inheriting the class Transient model, not the Model class.

So the class is defined as a Transient Model and even if it saves the record, this data has a short-term validity or it remains in the database until the work is completed.

And finally, the action record,

Creating Wizard in Odoo

This action is called when button verify is clicked as seen above.

Creating Wizard in Odoo

And the corresponding function is,

Creating Wizard in Odoo

Also when the pop-up appears, when we click on the confirm button, the state changes to complete, and also the date entered in the wizard gets automatically updated in form view.

The function behind the confirm button is as shown below-

Creating Wizard in Odoo

This function has called another function and also the date value is passed to a field in form.

This is the function which was called, just to change the status of onboarding.

In simple words, wizards can be defined as a dialogue box in Odoo that is used for interaction. Wizard is generally defined as a Transient Model, where data are stored temporarily. Here we can take the inputs from the users and workout based on the business logic and requirement.