Help

0

How to set the options attribute in field in a conditional way?

Avatar
Ragav Y

I am trying to have a field that will have 'no_open' set to True if a given condition is true and have it be False otherwise.

I tried using domain filters...

<field name="partner_id" string="Contact Search" options="{'no_open': [('stage_type_name','=','Rejected)]}" />

My expectation was that the no_open will be set to False if the condition was false and to True if it is true. But it didn't work out. It sets it to true regardless of the output of the domain filter. Then I did this:-

<field name="partner_id" string="Contact Search" attrs="{'invisible' : [('stage_type_name', '=', 'Rejected')]}" />
<field name="partner_id" string="Contact Search Readonly" attrs="{ 'invisible' : [('stage_type_name','!=','Rejected')]}" options="{'no_open': True}"/> 

I thought this should fix the issue but unfortunately the options automatically get taken from the last instance of the field for that field name. So it takes the options field from whichever ends up at the bottom. Invisible simply hides it from view rather than render it invalid.

I would like to set the option to True or False depending on a certain condition based on the value of a certain value in the form.

2 Comments
Avatar
Discard
Avatar
Ibrahim Boudmir
-

In your second solution, did you try to put no_open: True in the fist field and then no_open:False in the second ? Because i see that you added no_open: True to both fields

Avatar
Ragav Y
-

@ibrahim, sorry that was a mistake in my question. I had tried it properly in the actual code. Fixed the code in the question as well.

1 Answer
0
Avatar
Chris TRINGHAM
Best Answer

This doesn't answer your second question, but it might help other people reading this.  

Some attributes can be made conditional, whilst other cannot. As you have observed, although it's possible to add a domain filter to no_open it is ignored whereas this works fine for invisible and others.

And no_open blocks the "External Link" (screenshot here)

Avatar
Discard