1


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?

ashwin mahajan
  • 1,654
  • 5
  • 27
  • 50

1 Answers1

0

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

danidee
  • 9,298
  • 2
  • 35
  • 55
  • If i recall correct Odoo will show the field content in the last field definition in a view. So the the first field definition should be useless. I think making the field invisible won't deal with that behaviour. – CZoellner Nov 24 '16 at 15:25
  • I really don't get what you mean....but from the domain filter only one field should be visible at a time, not both of them – danidee Nov 24 '16 at 18:05
  • It's hard to explain, sorry. Defining a field twice or more in a view will odoo only fill the fields content (e. g. a string for a char field) of the last defined field. But i don't know if invisibility changes this. – CZoellner Nov 24 '16 at 18:14
  • And more: the other fields are always empty. – CZoellner Nov 24 '16 at 18:15
  • I tried this but it does not work in case of an image. The image doesn't show up but a download link is provided in the other cases. – ashwin mahajan Nov 25 '16 at 11:44