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

How to write Domain in Python

By
Ajeng Shilvie
on 2/12/15, 3:43 AM 745 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

2
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
1
Sea
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

0
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 ..

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

2 follower(s)

Stats

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