Odoo Help


How to write a Domain in a filter? [SOLVED]

Yannick Gerard
on 5/7/15, 3:49 AM 1,721 views

Hello, I know my question seems kinda dumb (there is an attribute "domain" so what's the point ?) but here's my problem:

I created a default filter:

<filter string="My Validations" icon="terp-personal" name="my_validations"
domain="['|',('employee_id.parent_id.user_id','=', uid),'&amp;',('employee_id.coach_id.user_id','=',uid),('state', '=', 'validate1')]"
help="My validations"/>

with this domain, I have no problem, but it's not exactly what I want ... i want to add an other constraint: state = confirm so I tried many things and nothing worked (in order to have something like ( employee.parent AND state confirm) OR (employee.coach AND state validate1)

domain="['&amp;',('employee_id.parent_id.user_id','=', uid),'|',('state','=','confirm'),'&amp;',('employee_id.coach_id.user_id','=',uid),('state', '=', 'validate1')]" 

This one works, but only for the first part (employee.parent and confirm), the second one is not seen.

domain="['|',('&amp;',('employee_id.parent_id.user_id','=', uid),('state','=','confirm')),('&amp;',('employee_id.coach_id.user_id','=',uid),('state', '=', 'validate1'))]"  

This one throw an error " Invalid leaf ['&', ['employee_id.parent_id.user_id', '=', 316], ['state', '=', 'confirm']]"

domain="['|',['&amp;',('employee_id.parent_id.user_id','=', uid),('state','=','confirm')],['&amp;',('employee_id.coach_id.user_id','=',uid),('state', '=', 'validate1')]]"   

And this one throw an error "TypeError:results.groupby is undefined"

And I'm lost ... I don't know what to try now ...

Please ... Help ç_ç




| 6 5 7
Tbilisi, Georgia
On 5/7/15, 4:39 AM

a problem is that you're trying to use wrong notation, you've to write odoo domains using prefix notation.

The main advantage of prefixed/postfixed operators are to avoid to use brackets for determine a sequence of calculation. in these domains there is used prefixed notation, so each operator takes it's following operands. there is no need to use extra brackets.

I'll take fseudocode from your question and transform it step by step:

you wrote

in order to have something like ( employee.parent AND state confirm) OR (employee.coach AND state validate1)

(BTW you've written above statement using infix notation, in order to get worked it in odoo domains, we've to transform it into the prefix notation)

first transform statements in the brackets, move AND condition to the start of each of them:

(AND, employee.parent , state confirm) OR ( AND, employee.coach , state validate1) 

-here AND takes it's two following arguments, then it's caclulated and considered as argument for OR.  (same for another AND), now move the OR operator to the left of it's arguments:

OR, (AND, employee.parent , state confirm),( AND, employee.coach , state validate1)

but here brackets are extra, they can't determine anything in rapport of sequence of calculation, each AND takes it's following two operands(as binary operator), and OR takes it's following two operands as well (results of two AND). so now we remove brackets, and your fseudo statement will become something as:

OR, AND, employee.parent , state confirm, AND, employee.coach , state validate1

-it's prefix notation equivalent of your infix notation fseudostatement.

of course you'll have some other brackets in real domain statement, but not the ones used for sequence/prioritize calculations.

you'll have something like:

domain="['|','&amp;',('employee_id.parent_id.user_id','=', uid),('state','=','confirm'),'&amp;',('employee_id.coach_id.user_id','=',uid),('state', '=', 'validate1')]" 

About This Community

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


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 5/7/15, 3:49 AM
Seen: 1721 times
Last updated: 5/7/15, 5:18 AM