Odoo Help


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.


How to use on_change method to change/add fields in view?

Nate Greene
on 10/21/15, 2:09 PM 370 views

Is it possibly to use an on_change method based on a Product name (or any other field) to change or add fields in a view?  I've been trying to read up on this and I can see that it's possible to return values to other fields, but I haven't found yet whether it's possible to change the view itself (temporarily).  Thank you.


Akhil P Sivan

--Akhil P Sivan--
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 10/22/15, 12:00 AM


Using onchange method its not possible to create new fields on the fly, but you change the values of existing fields of your model. If you have 3 fields for your model, say fieldA, fieldB, fieldC and you define onchange method for fieldA, depending on changing the value of fieldA, you can set the value of fieldB & fieldC, but not possible to create a new fieldD.

But its possible to create similar effects, by predefining the extra fields and make them hide or visible depending on the value of another field, say Product name or category etc. But for that you don't need to use onchange method, you can use the attribute attrs in the xml file for that extra fields. For eg:

<field name="fieldB" attrs="{'invisible': [('fieldA','=','Nate')]}" />

Onchange is dealing differently in old api and new api, which you can found in the documentation, but the functionality remains same. But I think if your need to is to create fields(by hide/show effect), you may use attrs. And if you need to set/change values of other fields based on another, you can use the onchange method.

Hope this helps.

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)


Asked: 10/21/15, 2:09 PM
Seen: 370 times
Last updated: 10/22/15, 7:43 AM