Odoo Help


How can i return act_window with context in function on_change ?

Mostafa Abd El Fattah
on 8/25/16, 8:30 AM 1,051 views
def onchange_stage_id(self, cr, uid, ids, stage_id, context=None): 
# open a new act window to display
    if stage.name == 'Proposal':
         print stage.name 
        return {
            'type': 'ir.actions.act_window',
             'res_model': 'sale.order',
             'view_type': 'form',
             'view_mode': 'form',
             'target': 'new',
when i do this onchange i got an error

onchange_stage_values = self.onchange_stage_id(cr, uid, ids, vals.get('stage_id'), context=context)['value']

KeyError: 'value'

FYI I think you may be missing browse wiith the stage_id to get the stage.

Mai Ecarde
on 10/9/16, 8:47 PM

Techno-Functional Associate with 7+ years of experience in Odoo (formerly known as OpenERP).

On 8/26/16, 3:17 AM

You are getting such error because of this code

self.onchange_stage_id(cr, uid, ids, vals.get('stage_id'), context=context)['value']

onchange_stage_id is not returning any dict having "value" as its key/item hence you got that error,

so you can handle it in 2 ways:

 1.  declare/initialize "value" in the return dict of the onchange function to ensure that it always returns "value" least dummy value.

Something like this

def onchange_stage_id...
res['value'] = {} # initialize res at the start of the function

2. Or you could rewrite your code like

x = self.onchange_stage_id(cr, uid, ids, vals.get('stage_id'), context=context)

onchange_stage_values = x.get('value', {})

x.get('value', {}), this syntax will first try to fetch the key "value" from the dictionary "x", if none found it will return second param i.e {}

I will check that.

Mostafa Abd El Fattah
on 8/31/16, 8:31 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

1 follower(s)


Asked: 8/25/16, 8:30 AM
Seen: 1051 times
Last updated: 11/5/16, 1:56 AM