Odoo Help


Wizard and context values in OpenERP 7

Francesco OpenCode
on 3/25/13, 2:50 PM 13,248 views

When I read the context in the functions of a wizard, I found that active_id is the wizard id. In the old openerp version, this parameter was the form id when i call wizard! It'a a bug or a feature? There is a system to read the calling form id?

Francesco OpenCode
On 3/26/13, 6:33 AM

I found my problem!!! I created a multi-step wizard. After the first step, I forgot to pass context to new step. Therefore, the context was replaced by a standard context where active_id was wizard id. Now I've replaced my old code with this:

return {
 'type': 'ir.actions.act_window',
 'name': "Inserisci Ispezioni Settimanali",
 'res_model': 'gmc.inserisci_ispezioni_settimanali',
 'res_id': ids[0],
 'view_type': 'form',
 'view_mode': 'form',
 'view_id': view_id,
 'target': 'new',
 'nodestroy': True,
 'context' : context,

and now work fine.

But...with this you are getting the id of the wizard, not the form id of the caller. I think I am understanding the answer incorrectly.

on 3/26/13, 8:24 AM

Hi I am also having problem in calling form through my button . Plz help

on 7/18/13, 1:12 AM
On 3/25/13, 3:27 PM

I can not say if this is a bug or a feature actually, but to solve this I had to override the default_get function of the wizard.

E.g. Lets assume we want to set a field something of the caller.model object calling a wizard. In field called caller_id we will put the caller's id, not showing it in any view. Now let us assume that the function action_of_wizard is the one that does 'the magic' and is called when pressing a button.

Then in wizard .py:

_columns = {    
    something: fields.char("Data to write in the caller's field", required=True),
    caller_id: fields.integer('Caller ID', readonly=True),

def default_get(self, cr, uid, fields, context=None):
    ret = super(wizard_model_name,self).default_get(cr, uid, fields, context=context)
    caller_id = context.get('active_id',False)
    if caller_id:
        ret['caller_id'] = caller_id
    return ret

def action_of_wizard(self, cr, uid, ids, context=None):
    caller_pool = self.pool.get('caller.model')
    for wiz in self.browse(cr,uid,ids,contex=context):
        caller_pool.write(cr, uid, wiz.caller_id, {'caller_field': wiz.something})
    return {'type': 'ir.actions.act_window_close'}

There are some possible improvements to make to the code, of course, but I hope I made myself clear from the above example!

Hope this answer suits your enquiry!

This is not a solution for me because I need form id to write some datas in the record and not to set wizard field.

Francesco OpenCode
on 3/25/13, 3:52 PM

I updated my answer to do what (I think is what) you want.

on 3/25/13, 4:41 PM

I think you mean default_get(), not get_default()

Mohammad Alhashash
on 3/25/13, 4:59 PM

My bad! :P Sorry

on 3/25/13, 5:01 PM

No guys. This is not my case. I need to write wizard datas in form fields. But i haven't the form id in wizard context.

Francesco OpenCode
on 3/26/13, 5:59 AM

Exactly, you wont have it in the context once the wizard is loaded, but before (when calling default_get) you can access the ID of the form as stated in the answer, save it an integer field of the wizard and use it again when you need it. I can not see why this is not working, it does in my case at least.

on 3/26/13, 8:19 AM

You do not need to override default_get() to set a field value. Just add default_FieldName to the context attribute.

Mohammad Alhashash
on 3/26/13, 9:08 AM

Yes, this is true, you can do it like this. It did not occur to me but this is probably simpler if the only thing you want to do is access the id of the caller. I did that way but because in my case I was doing other calculations as well. Thanks for pointing this

on 3/26/13, 9:20 AM
Mohammad Alhashash
On 3/25/13, 5:18 PM

If you are using a button to open the wizard, you can control the default values of the wizard fields using context variables in the format default_FieldName.

So, If the wizard has a field called target_id; In your model, you should start the wizard using a method button like this:

def action_start_wizard(self, cr, uid, ids, context=None):
    if context is None:
        context = {}
        'default_target_id': len(ids) and ids[0] or False
    return {
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'mymodule.mywizard',
        'type': 'ir.actions.act_window',
        'target': 'new',
        'context': context,
        'nodestroy': True,

Then, use the target_id field in your methods instead of context['active_id']. Of course you should make target_id field invisible in the wizard view.

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: 3/25/13, 2:50 PM
Seen: 13248 times
Last updated: 3/16/15, 8:10 AM