Odoo — Make the whole form view read-only based on context or session

Rameshwor Dhakal
Bajra Technologies Blog
2 min readNov 20, 2019

--

Make whole form readonly in Odoo

Once a scenario came where I had to make the whole form view read-only. I searched everywhere and tried to add readonly=0 on <form> tag which obviously didn’t work. Then after some study, I came across a solution where I was able to make the whole form read-only by passing a context or session.

This was done through the use of fields_view_get() method which is basically loaded every time when the view is loaded. The thing to be careful when using this method is that we can not get any data related to the respective record inside this method as it is called when loading the view (at that time, the data of the record is not loaded).

For example, we cannot get the id of that record from code self.id

Now, let’s get to the point. Let’s study the code thoroughly with the comments.

I hope, you have understood all the codes :)

The above code is similar to adding read-only in each field in the form view but in a cleaner way.

Update: Later, I also found this feature in Odoo which may have been introduced recently. You can pass a form read-only flag while opening the act-window.

--

--

Software Engineer, a tech enthusiast, an open-source lover, and a good human being.