Odoo Help


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.


How can i return act_window with context in function on_change ?

Mostafa Abd El Fattah
on 8/25/16, 8:30 AM 271 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


| 5 4 7
Bengaluru, India

Techno-Functional Associate with 6+ 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

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

1 follower(s)


Asked: 8/25/16, 8:30 AM
Seen: 271 times
Last updated: 8/26/16, 3:17 AM