This question has been flagged
5 Replies
6269 Views

I'm trying to override an onchange method, on account_voucher model, so as to add a new field return, for the field "encaisseur".

It's a new field that I added,  and it a many2one to res.users. like this : 

'encaisseur': fields.many2one('res.users','Commercial', required=True, ondelete='cascade'),
 

Here after the code for the onchnge method I tried to do : 

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

        res = super(AccountVoucher, self).onchange_partner_id(cr, uid, ids, partner_id, journal_id, amount, currency_id, ttype, date, context=None)  
        res.update({'value': {'encaisseur': False}})
        commercial = False 
        if partner_id:
            partner = self.pool.get('res.partner').browse(cr, uid, partner_id, context)
            commercial = partner.user_id
            res.update({'value': {'encaisseur' : commercial}})
       return res

When trying to change a partner so as to give me its commercial, it pop ups an XML http request error like this : 

XmlHttpRequestError INTERNAL SERVER ERROR

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <title>500 Internal Server Error</title> <h1>Internal Server Error</h1> <p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p

Any suggestions please ? where I did it wrong ? thanks

Avatar
Discard
Best Answer

Everything is correct, however, the result returned from the Standard onchange_event will be of form {'value':{}}

And you are trying to update the original value list.. but it should be like this..

res['value'].update({'encaisseur': False})

 


 

Avatar
Discard
Author

I tried this, and for : res.update({'value': {'encaisseur' : commercial}}) too, I made : res['value'].update({'encaisseur': commercial}), it returns empty values for the field encaisseur, but no errors, so you are right for the return format, but why it returns false for the field 'encaisseur' ?

Author

Correction : Same result with changes suggested. I was testing wrong sorry.

Author

I was just missiing "id" on : commercial = partner.user_id, I should put : commercial = partner.user_id.id , what a shame ! thanks deep :)

Best Answer
Avatar
Discard