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.

1

What should onchange methods return?

By
Torvald Baade Bringsvor
on 11/26/14, 8:43 PM 788 views

Seems the forum has some bugs, I was unable to enter text for the question. I'm on V8 so I'm after what has changed from V7 to V8. I have tried returning {'value' : {'fieldname etc... but the response that is returned to the client has another dictionary for 'value', with only some of the values changed in this onchange method.

Torvald Baade Bringsvor
on 11/27/14, 2:27 AM
2

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
3577
| 5 4 9
Pondicherry, India
--Dhinesh - Technical Consultant, Sodexis Inc--

Passionate coder in Python/OpenERP. Knows Django/Flask MVC frameworks. Did code in Java, PHP.

Contact me at: dvdhinesh.mail@gmail.com

Dhinesh - Technical Consultant, Sodexis Inc
On 11/27/14, 3:11 AM

Hi, try this for V8 onchange api.

    @api.onchange('field_name')
    def onchange_field_name(self):
        value = self.field_name if self.field_name else 'Nothing'
        return {'value': {'field_name': value}}

You can return the value in self itself like,

    @api.onchange('field_name')
    def onchange_field_name(self):
         self.message = "Dear %s" % (self.field_name or "")

The second approach works, but only for the field that triggered the onchange. If I want to update another field (a different column in a tree view) nothing happens. The first approach with the dictionary I'm not able to make work at all, I've looked at the response in Chrome and the values returned are the fields that have been modified in the onchange.

Torvald Baade Bringsvor
on 11/27/14, 5:20 AM
2

Baiju

--Baiju--
3154
| 5 4 8
Kochi, India
--Baiju--
ODOO technical and functional

        I like learning new thing, especially technical thing. I am a quick learner, I can learn technical things very fast. I have good logical skill,  I have immense interest in programming.

e-mail id : baijuks@hotmail.com

Baiju
On 11/26/14, 11:05 PM

Hi,,

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

{

'warning': {'Your Message'},

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

}

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: 11/26/14, 8:43 PM
Seen: 788 times
Last updated: 3/16/15, 8:10 AM