Odoo Help


[V8] Change view based on current model

Aurélien Rivet
on 3/21/16, 5:18 AM 475 views


I want to use one wizard to act on multiple models. Depending on the model the wizard acts on, some fields of the form view have to change. Currently, I have created two views and choose the one I would like to use using the view_id attributes on the action associated to each model. But I have to create two views and this is not very "DRY". Is there any way to get the current model from xml and make some part of the form view visible/invisible depending on it ?

--Ahmed M.Elmubarak--

Ahmed M.Elmubarak
On 3/21/16, 7:56 AM


You can use the action's context to achieve that ...


if you've two models model-1 and model-2, you can create two boolean fields [this is just to illustrate the idea] model1, and model2

make them invisible in the wizard's form.

then in your action [e.g for the first model] define the context as :

<field name="context">{'default_model1':1}</field>

And in the wizard's form make your fields invisible depends on that e.g:

<field name="field1" attrs="{'invisible': [('model1', '!=', True)]}"/>

Hope this will help

Hi and thanks for your response. Yeah it seems to be the right way to do it.

Aurélien Rivet
on 3/21/16, 8:39 AM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/21/16, 5:18 AM
Seen: 475 times
Last updated: 3/21/16, 8:39 AM