Odoo Help


[v7] getting wizard ID

on 10/26/13, 4:50 AM 2,131 views

How to get wizard id in onchange method? Do you know some trick to do this? I searched for examples in standard modules but without answer.

class some_wizard(osv.osv_memory):    
     _columns = {
        'some_string': fields.char('Some string', size=256),

def default_get(self, cr, uid, fields, context=None):
    ret = super(some_wizard,self).default_get(cr, uid, fields, context=context)
    print 'default_get', ret, context
    # 'default_get'
    # ret: []
    # context: {'lang': 'en_US', 'tz': 'Europe/Brussels', 'uid': 1}
    return ret

def onchange_some_string(self, cr, uid, ids, some_string=None, context=None):
    print ids, context
    # context : {'lang': 'en_US', 'tz': 'Europe/Brussels', 'uid': 1}
    # ids: []
    return {}

<record id="" model="ir.ui.view">
            <field name="name"></field>
            <field name="model"></field>
            <field name="arch" type="xml">
                <form string="some_string" version="7.0">
                        <field name="some_string" on_change="onchange_some_string(some_string,context)" />
                        <button string="Cancel" class="oe_link" special="cancel" />

Brett Lehrer

--Brett Lehrer--

| 5 5 8
Milwaukee, United States
--Brett Lehrer--
Director of IT and open source enthusiast.
Brett Lehrer
On 10/26/13, 5:02 AM

You can't get the wizard ID from an onchange event if the wizard record doesn't exist yet. The wizard won't exist in the database until you click a button, either to complete the wizard or move to the next screen.

The trick to get around this issue is to create the wizard record before opening the view for it. To do that, use an object button instead of an action button and create a function that generates the wizard record and returns a dictionary action to open it on that newly created id. For your view XML, just:

<button type="object" string="Start Wizard" name="start_wizard"/>

The function in your source object (not the wizard object)

def start_wizard(self, cr, uid, ids, context=None):
    if context is None: context = {}
    active_rec = self.browse(cr, uid, ids[0])
    # Pass in any values here that you want to be pre-defined on the wizard popup
    values = {}
    wizard_id = self.pool['some.wizard'].create(cr, uid, values)
    return {
        'name': 'Some Wizard',
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'some.wizard',
        'res_id': wizard_id,
        'type': 'ir.actions.act_window',
        'target': 'new',
        'context': context,

When you get to the onchange function in the wizard, you'll be able to use the id.

Thanks for fast answer. It solves a problem.

on 10/26/13, 5:22 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 10/26/13, 4:50 AM
Seen: 2131 times
Last updated: 3/16/15, 8:10 AM