Blog

News & Events, Quick Tips
WIZARDS IN ODOO15 – AN OVERVIEW
April 1, 2022
Wizard In Odoo
Wizards are used for interacting in Odoo. In Odoo, wizards are of two types. They are:- Transient Model
- Abstract Model
Transient Model:
It is based on the transient model class. The data stored in the database is temporary in this class which periodically clears data from the database table.Abstract Model:
Most of the models in Odoo are based on this model class. The data stored in the table created are permanent until it is deleted. Wizards are an important part of every module. Here let us take a look at how to create a simple wizard. Here in this example, I am going to generate a wizard in the reporting menu on the sale order.
Next, we will discuss the code used to Generate the Wizard in Odoo. For that, we have to create the py and xml.

Here a model is defined Product Wise Sale Report.Then added two fields
- User_ids, which is a Many2many field of res.users.
- Product_id, which is a Many2one field of product.product.



IMPORTING A FILE THROUGH WIZARD IN ODOO
We can upload and import files through the wizard. Let us see how this can be done. First of all, take a look at the code in the py file.class YourWizard(models.TransientModel): _name = 'your_wizard' # your file will be stored here: csv_file = fields.Binary(string='Upload your File', required=True) @api.multi def import_csv(self):# this will get executed when you click the import button in your form return {} Here a csv_file is declared. This is a field for uploading your file. This field is set as required, which means it needs to be filled. After that, a function is defined as import_csv. This is the function for importing the file that we have already uploaded in the wizard. So when we click on the import button, the uploaded file is imported.
Next we are going to see the xml file for this:
<odoo> <data> <record id="your_wizard_form" model="ir.ui.view"> <field name="name">your.wizard.form</field> <field name="model">your_wizard</field> <field name="arch" type="xml"> <form string="Import a csv file"> <group name="main"> <field name="csv_file" /> </group> <footer> <button name="import_csv" type="object" string="Import" class="oe_highlight"/> <button special="cancel" string="Cancel"/> </footer> </form> </field> </record> <record id="your_wizard_action" model="ir.actions.act_window"> <field name="name">Import a csv file</field> <field name="res_model"your_wizard</field> <field name="view_mode">form</field> <field name="target">new</field> </record> <menuitem id="your_wizard_menu parent="SOME_MENU_IN_PURCHASE” action="your_wizard_action" sequence="15" /> </data> </odoo>