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 a field's value on form load

By
Odooveloper (by Rui Franco)
on 9/28/16, 1:32 AM 239 views

I've got this situation in which a boolean field get's changed by the user. And, it gets saved.

But... whenever the form is loaded, that field has to be set to False. Notice that I am not referring to default value. No, the field's value has to be changed so, no matter what value was saved, it has to be reset to False the next time the form is loaded.


I thought about using a computed field that would change the other field's value but, despite the log tellng me the value had been changed, nothing happened in the form.


An __init__, perhaps? Tried it but it was always raising an error. The model is product.template, BTW


1

Bejaoui Souheil

--Bejaoui Souheil--
808
| 2 1 4
Sousse, Tunisia
--Bejaoui Souheil--

Odoo developer,  functional and technical consultant

souheil_bejaoui@hotmail.fr

Bejaoui Souheil
On 9/28/16, 4:21 AM

Hi,

You can use the fields_view_get method of models.Model.

This method is called whenever odoo is rendering a view of the model.

It gets the correct view given the context and returns the data of the field.

This \tutorial may help.

http://elico-corp.com.sg/2015/10/01/how-to-tech-dynamically-modify-your-view/

Best regards.

Thanks Bejaoui. That's what I had done: I put a query inside this method But, somewhow, I believe there must be some more... "elegant" way of doing this.

Odooveloper (by Rui Franco)
on 9/28/16, 5:07 AM

For me, i use this method every time i need to dynamically modify a view based on some condition. You can find several examples in the standard addons.

Is there other way to do it? Possible, why not :)

Welcome.

Bejaoui Souheil
on 9/28/16, 5:31 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: 9/28/16, 1:32 AM
Seen: 239 times
Last updated: 9/28/16, 4:21 AM