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

[V8] Change view based on current model

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

Hi,

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 ?

0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


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

Hello,

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

e.g:

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

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: 3/21/16, 5:18 AM
Seen: 204 times
Last updated: 3/21/16, 8:39 AM