Odoo Help


How to write Domain in Python

Ajeng Shilvie
on 2/12/15, 3:43 AM 1,985 views

I want to define domain like this 

domain = A and B or C or (D and E)

name : fields.many2one('stock.production.lot,'No Engine',domain="[('branch_id','=',parent.branch_id),('tgl_penyerahan_bpkb','=',False),'|',('finco_id','=',parent.partner_id),('customer_id','=',parent.partner_id),('finco_id','=',False)]"),    

but it didn't show up , anyone can solve it ? Thanks in advance

Jordan Vrtanoski
On 2/12/15, 4:21 AM

The operators in the domain are prefix. Prefix notation requires the operators to be placed first and then the operands. This means that A and B should be translated in the prefix expression as and A B. Following this form, and based on you expression, this is the way to convert it to prefix and than writhe the domain:

A and B or C or (D and E) => and A B or C or (D and E) => or and A B C or (D and E) => or or and A B C (D and E) => or or and A B C and D E

So, the expression you need to write is or or and A B C and D E. There is convention that and can be omitted, so the final expression is:

or or A B C D E  which in code is ['|','|',('branch_id','=',parent.branch_id),('tgl_penyerahan_bpkb','=',False),('finco_id','=',parent.partner_id),('customer_id','=',parent.partner_id),('finco_id','=',False)]

I hope this helps. Prefix notation can be confusing for a first time, so here is a site that can help you understand the notation http://www.cs.man.ac.uk/~pjj/cs212/fix.html

actually my real code is like this " A and B and C and D or E or (F and G) " , how can i implement it ? it so confuse .. thank you

Ajeng Shilvie
on 2/12/15, 4:31 AM

A and B and C and D or E or (F and G) => or or and and and A B C D E and F G

Jordan Vrtanoski
on 2/12/15, 4:37 AM

ok i'll try it

Ajeng Shilvie
on 2/12/15, 4:48 AM

domain="['|','|','&','&','&',('penerimaan_bpkb_id','!=',False),('state_stnk','=','proses_stnk'),('branch_id','=',parent.branch_id),('tgl_penyerahan_bpkb','=',False),('finco_id','=',parent.partner_id),'&',('customer_id','=',parent.partner_id),('finco_id','=',False)]", It still didn't work , the field filtering data even the customer_id is not what i select in parent menu ..

Ajeng Shilvie
on 2/12/15, 4:57 AM

Check if your initial expression is correct. The A and B or C means (A and B) or C, so first A and B is evaluated. With other words, your expression can be read as (A and B and C and D) or (E) or (F and G), so if one of this three groups is true, the record will be presented.

Jordan Vrtanoski
on 2/12/15, 5:16 AM

yes Jordan , did i write the right code for it?

Ajeng Shilvie
on 2/12/15, 5:35 AM

thanks for your answer ,,,

Ajeng Shilvie
on 2/12/15, 5:53 AM
On 2/12/15, 4:19 AM

  Following is the example to implement the domain = A and B or C or (D and E)

domain = ['|', '|', '&', ('branch_id','=',parent.branch_id), ('tgl_penyerahan_bpkb','=',False), ('finco_id','=',parent.partner_id),
                        '&', ('customer_id','=',parent.partner_id), ('finco_id','=',False)]

--->Hope this help you

Ajeng Shilvie
On 2/12/15, 8:09 AM

i write this , domain="['&','&','&',('penerimaan_bpkb_id','!=',False),('state_stnk','=','proses_stnk'),('branch_id','=',parent.branch_id),('tgl_penyerahan_bpkb','=',False),'|',('finco_id','=',parent.partner_id),'&',('customer_id','=',parent.partner_id),('finco_id','=',False)]" and it works ..

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

2 follower(s)


Asked: 2/12/15, 3:43 AM
Seen: 1985 times
Last updated: 3/16/15, 8:10 AM