Odoo Help

Welcome!

This community 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.

1

[v7] getting wizard ID

By
asdf
on 10/26/13, 4:50 AM 1,461 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">
                    <group>
                        <field name="some_string" on_change="onchange_some_string(some_string,context)" />
                    </group>
                    <footer>
                        or
                        <button string="Cancel" class="oe_link" special="cancel" />
                    </footer>
                </form>
            </field>
        </record>
3

Brett Lehrer

--Brett Lehrer--
1252
| 5 4 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.

asdf
on 10/26/13, 5:22 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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