İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
5633 Görünümler
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'

Avatar
Vazgeç

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

En İyi Yanıt

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 {}

Avatar
Vazgeç
Üretici

I will check that.