Odoo ERP provides various tools to streamline business processes. Odoo Wizard is also one of the most useful features in Odoo. Basically, wizards are used for importing data, running batch operations, configuring complex settings, and performing advanced actions on records.
In this blog, we can explore how to create and manage a wizard on Odoo 18. Wizard data is not permanent. It will collect the records based on the inputs we are giving through the wizards. All users can access the wizard.
Begin by defining a transient model class for the wizard. You should also create a separate 'wizard' directory within your module structure.
from odoo import fields, models
class WhatsappSendMessage(models.TransientModel):
_name = 'whatsapp.send.message'
_description = "Whatsapp Wizard"
user_id = fields.Many2one('res.partner', string="Recipient")
mobile = fields.Char(related='user_id.mobile', required=True)
message = fields.Text(string="Message", required=True)
def action_send_message(self):
“””Type your code here”””
We need to create a view to open the wizard data using ir.actions—act_window. We can set a menu item or button action to initiate the wizard.
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">res.partner.view.form.inherit.whatsapp.redirect</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<!-- Add a WhatsApp button to the partner's form view -->
<xpath expr="//div[@name='button_box']"
position="inside">
<div class="oe_button_box" name="button_box">
<button name="action_send_msg" string="Whatsapp"
type="object"
class="oe_stat_button" icon="fa-whatsapp"/>
</div>
</xpath>
</field>
</record>
</odoo>
This XML snippet modifies the res.partner form view in Odoo by adding a new button to the button_box section. The button provides functionality to send messages directly from the form.
We need to specify the name, model name, and inherit_id.

We need to add the button function to view the wizard.
def action_send_msg(self):
"""This function is called when the user clicks the
'Send WhatsApp Message' button on a partner's form view. It opens a new wizard to compose and send a WhatsApp message."""
return {'type': 'ir.actions.act_window',
'name': _('Whatsapp Message'),
'res_model': 'whatsapp.send.message',
'target': 'new',
'view_mode': 'form',
'view_type': 'form',
'context': {'default_user_id': self.id}, }
- type: Defines the type of action to perform, in this case, opening a window.
- name: Sets the title of the window that will appear.
- res_model: Indicates the model that the action is linked to.
- target: Specifies that the window should open in a new dialog or tab.
- view_mode: Determines how the view will be displayed (e.g., form, tree).
- view_type: Describes the type of view being used.
- context: Provides additional context or parameters to the new window.
Next, we need to define the wizard's view using XML. The sample code is provided below.
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<!-- Odoo View Definition for Whatsapp Message Form -->
<record id="whatsapp_send_message_view_form" model="ir.ui.view">
<field name="name">whatsapp.send.message.view.form</field>
<field name="model">whatsapp.send.message</field>
<field name="priority" eval="8"/>
<field name="arch" type="xml">
<form string="Whatsapp Message">
<group>
<field name="user_id"/>
<field name="mobile"/>
</group>
<group>
<field name="message"/>
</group>
<footer>
<button name="action_send_message" string="Send" type="object"/>
<button name="cancel" string="Cancel" special="cancel"/>
</footer>
</form>
</field>
</record>
</odoo>
In the view, we need to specify the model name, and we can add the fields.

Conclusion
Creating and managing a wizard in Odoo 18 is a straightforward process, but it involves several key steps: defining a model, creating a form view, implementing the business logic, and linking the wizard to a user interface element. Wizards are powerful tools that improve the user experience by guiding users through complex tasks or multi-step processes. With Odoo 18, you can create highly customizable and intuitive wizards to suit your business needs.
To read more about How to Create & Manage Wizard in Odoo 17, refer to our blog How to Create & Manage Wizard in Odoo 17.