Monday 1 August 2016

How to Create Wizard on Odoo ?



https://dedyyuristiawan.blogspot.com/


Hello world. As i promise on this post How to Call Wizard from XML Button Odoo, i will share about wizard on Odoo. As you can see on previous post i just call wizard on the xml file. Now, i will share how to create wizard on Odoo. You know, wizard on Odoo is like pop up when in website, so in wizard data will save in memory, not in database Odoo. Usually we show wizard is for input additional data. So lets do it.

On this post, i just share wizard, if you want call wizard, you can read on this post How to Call Wizard From XML Button Odoo. So you can on my wizard.xml file bellow.

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="dedy_yuristiawan_wiz" model="ir.ui.view">
            <field name="name">dedy.yuristiawan.wizard.name</field>
            <field name="model">dedy.yuristiawan.wizard</field>
            <field name="arch" type="xml">
                <form string="Hi i am wizard">
                    <group>
                        <field name="name"/>
                    </group>
                    <footer>
                        <button name="create_request" 
                            string="Finished" type="object" 
                            class="btn-primary"/>
                        <button string="Cancel" 
                            class="btn-default" 
                            special="cancel" />
                    </footer>
                </form>
            </field>
        </record>

        <record id="action_view_wizard" model="ir.actions.act_window">
            <field name="name">Hi i am a wizard</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">dedy.yuristiawan.wizard</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="view_id" ref="dedy_yuristiawan_wiz"/>
            <field name="target">new</field>
        </record>
    </data>
</openerp>

Ass you can see, just 2 record on my xml file. On the bottom record i have name, type, model, view type, view mode, view_id, and target. The important is :

1. Type ir.actions.act_window it mean will show window like from view usually.

2. Res_model dedy.yuristiawan.wizard it's my model.

3. Target new it will show as new form, you can set current, it mean will show your current form.

4. View Id dedy_yuristiawan_wiz it will call top record as you can see. You know Odoo its run from Top to Bottom, That's why i put dedy_yuristiawan_wiz on the top (it mean, i make declaration first before i call it). 

5. On the Top record at  it look like similar with bottom record, i just add field, that i create on python file, and two button, button Cancel will dismiss this wizard and button Finish will call function create_request on my python file.

And this one, i call it python file.

from openerp import models, fields, api, _
from openerp.exceptions import UserError, ValidationError, Warning


class DedyYuristiawan(models.TransientModel):
    _name = "dedy.yuristiawan.wizard"
    
    name = fields.Char('Name', required=True)
    
    @api.multi
    def create_request(self):
        print "You click finish"

        return True

As you can see, the class have name models.TransientModel it mean wizard. And then i create field name that i call in  my xml file <field name="name"/> . Last i create function def create_request(self). That's i told you before, if want to call this function i create button Finish with this syntax <button name="create_request" string="Finished" type="object" button with name and type object.

That's it. So if want make wizard you can read first, you can create code python first and then xml code. Aha i forget something, Usually these file (python and xml) i put on folder Wizard, and the i declare on the __init__.py with include python file and then on __openerp__.py with this 'wizard/split_wo_wizard.xml' put on the top.

It real that's it. Aha. Just read first, if you still confuse about my code, you can write comment bellow. Thanks.
Share:

10 comments:

  1. Wow.. Greate... Simple..Thanks..

    can you add more tutorials about Odoo..plzz..

    ReplyDelete
  2. Simple and Good.

    It makes people to understand easily.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. greate its simple to easy

    ReplyDelete
  5. great.......
    i have a question..
    how to display the selected records in the tree view(checked) to be displayed in the wizard tree view

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. i am following your tutorials because your tutorials has step by step implementation and easy to understand. Thanks a lot buddy.

    ReplyDelete
  8. Very nice! Please give us more tutorials like this.)

    ReplyDelete
  9. hey i have a question anybody give me answer i have a many wizard in wizard so how can save data of wizard in tree view

    ReplyDelete


<br>


Advice for contacting me at dedyy54@gmail.com