Odoo Help

Welcome!

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.

0

Override Onchange Method : onchange_partner_id on account_voucher [v7]

By
Yassine TEIMI
on 2/23/15, 9:47 AM 1,108 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

1

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

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

deep
On 2/23/15, 10:05 AM

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

 


 

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' ?

Yassine TEIMI
on 2/23/15, 10:14 AM

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

Yassine TEIMI
on 2/23/15, 10:16 AM

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

Yassine TEIMI
on 2/23/15, 10:28 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)

Stats

Asked: 2/23/15, 9:47 AM
Seen: 1108 times
Last updated: 3/16/15, 8:10 AM