Odoo Help


find the edit/view state of a form view

HIGHCO - Nicolas Clavier
on 3/20/13, 7:53 AM 10,537 views

Hi, further to : a question I asked before I would like to know:

how can we deduct the state of a form (either edit or view mode) in xml view definition ?

I would like to use this information in a an attribute on field: example:

<field name="my_field" invisible="isTheViewInEditMode">
<field name="my_field" attrs="{'tree_invisible':[domain using isTheViewInEditMode]}">

René Schuster

--René Schuster--
| 5 5 8
Weinheim, Germany
--René Schuster--

Challenge Everything!

René Schuster
On 11/28/13, 6:00 AM

The Solution might be class="oe_edit_only".

<field name="yourfield" class="oe_edit_only"/>

This will hide the field, when view is in view mode. oe_edit_only also works for other design elements like labels, groups, etc..

To achieve the opposite (hide in edit mode), the answer to this question is very helpful and works fine for me:


René Schuster
on 12/17/13, 6:48 AM

Parth Gajjar

--Parth Gajjar--

| 3 3 5
Ahmadabad, India
--Parth Gajjar--
Parth Gajjar
On 3/21/13, 2:58 AM

First thing i can not understand well what you want to do but i try to do what i understood.

I add attrs field in sale order lines like this

<field name="discount" attrs="{'invisible':[('price_unit','=',0)]}" groups="sale.group_discount_per_so_line"/>

This means my discount field become invisible if price_unit = 0 And that's working See in image

image description

And if you wish user can see the field but can't edit then better use readonly attribute

Hope this will help you

Hey Parth, Thanks for your answer, my goal is the following: in a listview child of a form view (one2many widget) I have one fields.text that holds a lot of text. Since there is no option to truncate the text shown when the whole form is in view mode, I did as advised in another post. I created a fields.function that returns a truncated version of my fields.text. Now, I want to have the fields.text to be visible in the listview when the form is in edit mode only, and the fields.function (truncated text) to be visible when the form is in view mode.

HIGHCO - Nicolas Clavier
on 3/21/13, 5:54 AM

in the previous post mentionned in my question, someone advised setting the invisble attribute with invisible="context.get('set_editable',False)" but I found out that the set_editable key is not in the context. Therefore I want to clarify within this post : is there a way to find out in what state (edit|view) a form is at all ?

HIGHCO - Nicolas Clavier
on 3/21/13, 6:08 AM

Means you want to enable and disable whole column during switching between edit and saved mode .... I don't know about Is there a way to find out in what state (edit|view) a form is at all ?

But one other thing is pass class="oe_edit_only" this will disable field in saved mode and display that field in edit mode. but i never try that on one2many. Try it and see what happen

Parth Gajjar
on 3/21/13, 8:42 AM

that was a good track at first but so far it has no effect. Though the css trick should be investigated. I actually tried it on a label and it didn't affect visibility, even though the class was on the dom element.

HIGHCO - Nicolas Clavier
on 3/21/13, 10:55 AM

correction : it does work on a label, I had initially tested on a validated sale.order that could not be edited anymore, therefore not in edit mode. But on a draft sale.order it worked on a label. It still doesn't work on a table column though.

HIGHCO - Nicolas Clavier
on 3/21/13, 11:00 AM

Then there are 2 options .........

First made own widget(this is hard) .......

Second easiest way is use Jquery And JavaScript

For Local Jquery and javascript See this link Local CSS,JQuery and javascript in Openerp

Parth Gajjar
on 3/22/13, 9:48 AM

ok, so no easy way then. Thanks for the help anw !

HIGHCO - Nicolas Clavier
on 3/22/13, 12:14 PM

Back to this topic, I looked through the CSS but didn't spot a class that does the opposite like class="oe_browse_only" ... any hint ?

HIGHCO - Nicolas Clavier
on 3/26/13, 11:55 AM
Dr Obx
On 6/18/15, 11:17 AM

Even a couple of years later I found it very useful. It still can help :)

Currently added an image which is overlapping product avatar but while editing record I couldn't add/change avatar because product avatar was covered by the image i added :)

So I was needed something to solve this issue. Right  after I added this class="oe_edit_only" overlapping image gets hidden so i can add/change product's avatar now :)

in edit mode:

in view mode:

"in stock"

in view mode:

"out of stock"

Thank you guys :)

I'd love to see some example code of this Dr Obx!

Atte Isopuro
on 7/27/15, 9:37 AM
What do you mean ?
Example of what ?

On 27 July 2015 at 15:37, Atte Isopuro <atte.isopuro@web-veistamo.fi> wrote:

I'd love to see some example code of this Dr Obx!

Atte Isopuro
Sent by Odoo S.A. using Odoo about Forum Post False

Dr Obx
on 7/27/15, 10:50 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

2 follower(s)


Asked: 3/20/13, 7:53 AM
Seen: 10537 times
Last updated: 9/8/16, 2:06 AM