This question has been flagged
1 Reply
13299 Views

Hello everyone,

I am using Odoo 12 for this purpose
I am having a problem that seems to easy to solve but I simple do not understand where is the problem.

I have a button for which I need to set visibility based on 2 conditions. In this case I am using the button "attributes".

 The conditions are based on 2 fields and if I test the attribute using only one condition at a time, it works as expected:

      Condition 1: ... attrs="{'invisible':[('active','=', False)]}" ...
      Condition 2: ... attrs="{'invisible':[('state','!=','confirm')]}" ...

 In the example above, using the first condition, the button is only shown for all active records. And for the second condition, the button is only shown on records which "state" field is not 'confirm'. So I can confirm that conditions work as expected.

Now, I need to join both conditions on the same button attribute in order to test them with AND operator. I have tried:

     ... attrs="{'invisible':[('active','=', False),('state','!=','confirm')]}" ...

Does not work and also tried with ('state','not in','confirm') and ('active','!=', True).
There's no errors but I am sure none of the conditions is being applied and the button is shown everywhere.

Tried to use a '&':

     ... attrs="{'invisible':['&',('active','=', False),('state','!=','confirm')]}" ...

but I get an error 'doc = etree.parse(xmlfile)....'

Tried to use the corresponding special html character for &  ( & ).
The same result as the first situation. No errors but the conditions are not working.

What could be wrong?

I can ensure that I have records that must meet any of the conditions.

Thank you very much

Regards

PM

Avatar
Discard
Best Answer

use  attrs="{'invisible':['|', ('active','=', False),('state','!=','confirm')]}"

i believe what you need is an 'or' condition . remember that you are trying to make it invisible for both cases , so it is an 'or' condition and not an 'and' condition

invisible if condition 1 'or' condition 2

 


 

Avatar
Discard
Author

Dear @Anoop, thank you for the reply.

In fact I do want to make invisible for both cases. I do not need an OR condition. I need an AND condition in order to hide records that meet both conditions.

Thank you

Did you try the fields view get option and checked what is getting loaded as attrs for this field?

Author

Sorry everyone, sorry @Anoop,

I found the problem.

It is not related with the code it self. The problem is on the argument I was using for running Odoo server.

In order to prevent to always restart the server (with -u module_name argument) for the xml changes to be effective, I was using the --test-enable argument also.

This allows me to see the changes immediatelly just by refreshing the browser (besides running tests if they exist).

For some reason I don't know, the AND condition is not being correctly read with this argument.

Remove it and the code is working

...today's lesson: in case of doubt, review the start-up arguments and mannually upgrade the modules.

Thank you all once again

PM