Enable Dark Mode!
how-to-create-and-manage-wizard-in-the-odoo-16.jpg
By: Aswathi pn

How to Create & Manage Wizard in the Odoo 16?

Technical Odoo 16

Wizards are very useful for creating a good user experience. In all businesses, interactive sessions are most beneficial. To improve the user experience, wizards in Odoo provide an interactive session.
For creating wizards, we can use transient models or abstract models. This gives features of a model class except the data storing. Transient and abstract models have permanent database persistence. For them, database tables are made, and the records in such tables are kept until they are specifically erased.
Instead of models, a wizard is a model that extends the class Transient Model. With the following specificities, the class TransientModel extends models and reuses all of its current mechanisms:
1. Wizard data are not permanent; they are automatically removed from the database after some time. 
2. Users have all access to wizard data.
3. Wizard records may allude to regular data or wizard data through many2one fields, but regular data cannot allude to wizard data through a many2one field.
First of all we have to create a transient model class for creating the wizard. And also, create a directory named wizard on your module.
from odoo import models, fields, api
class TestWizard(models.TransientModel):
   _inherit = 'test.wizard'
   name = fields.Char(string='name')
Also, don’t forget to add the model to the security file and give the required permissions.
Next, we have to create a view for that wizard to show. Wizards are always to open as ir.actions.act_window data. A menu item or button action written in either Python or XML code can initiate the wizard action.
To open a wizard, we can create a menu item. For that, we can use the code below.
<menuitem id="test_wizard_menu" 
sequence="10"
 name="Wizard" action="test_wizard_action"/>
id: is the id of the menu item that will be unique for each menu item.
sequence: is the position of the menu item showing on the dropdown.
name: name of the menu item.
action: action of the menuitem that will be clicked on the menu.
Next, we can add an action for the menu.
<record id="test_wizard_action" model="ir.actions.act_window">
        <field name="name">Test Wizard</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">test.wizard</field>
        <field name="view_mode">form</field>
        <field name="view_id"              ref="test_wizard_view_form"/>
        <field name="target">new</field>
</record>
id: is the id of the record that will be unique for each record
model: model of the record. 
name: action name
type: type of the action, the view’s actions are commonly ir.actions.act_window
res_model: this specifies on which model this action will perform.
Next, we have to create a view to show the wizard. For that, we can use the following code.

<record id="test_wizard_view_form" model="ir.ui.view">
        <field name="name">test.wizard.form</field>
        <field name="model">test.wizard</field>
        <field name="arch" type="xml">
            <form string="Test Wizarf">
                <group class="oe_title">
                    <field name="demo_feild"/>
                </group>
               </form>
        </field>
    </record>
On the view, mainly we can specifies the name model and also the fields which are showing on the view. The view is commonly under the model ir.ui.view
If you do not specify the footer, the footer will show the default ok button. If you want to add more buttons, use the following code.
<footer>
    <button string="Cancel" class="btn-secondary"         special="cancel"/>
<button name="action_done" string="Submit" type="object" class="btn-primary"/>
</footer>
This is how we can create a wizard in Odoo 16 platform.


If you need any assistance in odoo, we are online, please chat with us.



1
Comments

Yaser

Hola. Como puedo crear un reporte qweb desde mi wizard?

06/07/2023

-

4:30PM



Leave a comment

 


whatsapp
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message