Skip to Content
Menu
This question has been flagged
3 Replies
3425 Views

hi

I write this function in account voucher module :

----------------------------------------------------

 

def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id, amount, currency_id, ttype, date,section_id, context=None):

     if not journal_id:

         return {}

     res = self.recompute_voucher_lines(cr, uid, ids, partner_id, journal_id, amount, currency_id, ttype, date, context=context)

     vals = self.recompute_payment_rate(cr, uid, ids, res, currency_id, date, ttype, journal_id, amount, context=context)

     for key in vals.keys():

          res[key].update(vals[key])

     return res

     section_id = False

     if partner_id:

          section_id = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context).section_id.id

     return {'value': {'section_id' : section_id}}

-----------------------------------------------------------------

but when I test it,

also 'for loop' is run. and 'if partner_id' doesn't run. I don't know what is problem?

I think problem is that I don't know haw can return multi value in one function.?!!


Thanks

Avatar
Discard

please include which version(v7,v8orv9) are you using?

Best Answer

Hi,

Python ignore the code after "return res".

     for key in vals.keys():

          res[key].update(vals[key])

     return res #check where to put this line

     section_id = False

     if partner_id:

Thats why

'for loop' is run. and 'if partner_id' doesn't run

Avatar
Discard
Author

hi yes, I know this problem is from 'return res'. but I don't know how can edit this code that resolve the problem? :( can you help me? Thanks

Best Answer

Hi Nasim,

You are using old API.

onchange method in old API should return a dictionary in following format :-  Eg:

{

'warning': {'Your Message'},

'value': {'field_name1': VALUE , 'field_name2': VALUE, 'field_name3': VALUE}

}


Hope this helps.

Avatar
Discard