Odoo Help

Welcome!

This community 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.

0

Correct way to make domains for multiple or conditions?

By
Yenthe
on 2/12/16, 8:10 AM 778 views

Hi guys,


I'm having some issues with domains. I know I can use | if I have an or condition. Initially I had the following code:

<field name="gebruik_zorgverlener_adres" attrs="{'invisible': ['|',('gebruik_organisatie_adres','=',True),('gebruik_prive_adres','=',True)]}"/>

<field name="gebruik_organisatie_adres" attrs="{'invisible': ['|',('gebruik_zorgverlener_adres','=',True),('gebruik_prive_adres','=',True)]}"/>

<field name="gebruik_prive_adres" groups="my_module.group_sel_manager" attrs="{'invisible': ['|',('gebruik_zorgverlener_adres','=',True),('gebruik_organisatie_adres','=',True)]}"/

Which is basically saying that when one of those fields is checked on that all others should become invisible. This piece of code works fine!
When I now add a fourth field and add another or condition to all those attrs it will not however. My attempt:

<field name="gebruik_zorgverlener_adres" attrs="{'invisible': ['|',('gebruik_organisatie_adres','=',True),('gebruik_prive_adres','=',True), ('gebruik_maatschappelijke_zetel_adres','=',True)]}"/>

<field name="gebruik_organisatie_adres" attrs="{'invisible': ['|',('gebruik_zorgverlener_adres','=',True),('gebruik_prive_adres','=',True), ('gebruik_maatschappelijke_zetel_adres','=',True)]}"/>

<field name="gebruik_prive_adres" groups="my_module.group_sel_manager" attrs="{'invisible': ['|',('gebruik_zorgverlener_adres','=',True),('gebruik_organisatie_adres','=',True), ('gebruik_maatschappelijke_zetel_adres','=',True)]}"/>

<field name="gebruik_maatschappelijke_zetel_adres" attrs="{'invisible': ['|',('gebruik_zorgverlener_adres','=',True),('gebruik_prive_adres','=',True), ('gebruik_organisatie_adres','=',True)]}"/>

I simply added another field to all those or conditions for all fields but yet this totally fails. When I now test this code not one checkbox will be hidden or shown depending on what I do.
So, what is the correct way to write an or domain so that always only one of those four checkboxes is shown to the user? and is there no other way to write the domain then by calling ALL other field names? There must be a shorter way to code this?

Thank you,
Yenthe

as "or" operator '|' is a default one, it's not necessary to use it here at all. Try to write all the same domains without any operator, remove all '|'-s, like this:

 attrs="{'invisible': [('gebruik_organisatie_adres','=',True),('gebruik_prive_adres','=',True), ('gebruik_maatschappelijke_zetel_adres','=',True)]}" 
Temur
on 2/13/16, 4:04 AM

@temur, default operator is AND !

Jérémy Kersten (jke)
on 2/13/16, 3:48 PM
1

Axel Mendoza

--Axel Mendoza--
10238
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 2/12/16, 11:06 AM

@Yenthe

Your domains could be get it fixed by adding another '|', like:

<field name="gebruik_zorgverlener_adres" attrs="{'invisible': ['|','|',('gebruik_organisatie_adres','=',True),('gebruik_prive_adres','=',True), ('gebruik_maatschappelijke_zetel_adres','=',True)]}"/>

<field name="gebruik_organisatie_adres" attrs="{'invisible': ['|','|',('gebruik_zorgverlener_adres','=',True),('gebruik_prive_adres','=',True), ('gebruik_maatschappelijke_zetel_adres','=',True)]}"/>

<field name="gebruik_prive_adres" groups="my_module.group_sel_manager" attrs="{'invisible': ['|','|',('gebruik_zorgverlener_adres','=',True),('gebruik_organisatie_adres','=',True), ('gebruik_maatschappelijke_zetel_adres','=',True)]}"/>

<field name="gebruik_maatschappelijke_zetel_adres" attrs="{'invisible': ['|','|',('gebruik_zorgverlener_adres','=',True),('gebruik_prive_adres','=',True), ('gebruik_organisatie_adres','=',True)]}"/>

The thing is that you need to put all the operators in the beginning of the domain to be used like an stack to be matching the domain terms.

Thanks a lot Axel, great answer.

Yenthe
on 2/26/16, 2:29 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/12/16, 8:10 AM
Seen: 778 times
Last updated: 2/13/16, 3:49 PM