ODOO : Set specific value of an attribute in attrs

1.6k Views Asked by At


I am trying to display attachment in the form view. Based on the type of attachment I want to change the value of widget. If attachment is an image then widget="image".
My doubt is if we write something like this:

attrs="{'invisible' : [('state', 'in', ('new','assigned'))] , 'readonly' : [('state', 'not in', 'assigned')]}"

This will set the invisible and read_only properties to true since they are boolean or have just two values. How can we set an attribute to a specific value.
Also, can we use widget to display video attachment in the form view?

1

There are 1 best solutions below

5
On

You can create two fields with different widgets and make them visible based on the condition in your domain

<field name="attachement" attrs="{'invisible' : [('state', 'in', ('new','assigned'))] , 'readonly' : [('state', 'not in', 'assigned')]}" widget="image" />

<field name="attachement" attrs="{'invisible' : [('state', 'not in', ('new','assigned'))] , 'readonly' : [('state', 'not in', 'assigned')]}" />

At any point in time only the field with the right widget would be shown based on the condition in your domain.

As for your second question. personally i've never had the need to embed a video within a form in Odoo.

but embedding <video></video> tags should work