Skip to Content
Menu
This question has been flagged
2 Replies
24017 Views

Explaination of Odoo domain filter with simple example

Avatar
Discard

Thanks. I have a model (Agreement) that has a contact on it. I've created a many2one field on my invoice model to link invoices to agreements. What I want is if you go to select an agreement for an invoice it only shows the agreements for that contact.
I've tried [["x_studio_partner_id","=","res.partner.id"]] & [["x_studio_partner_id","=","partner.id"]] &
[["x_studio_partner_id","=","id"]]

Author Best Answer

Consider the following fields in XML view.




Single condition:
Simple condition in programming:

if field1 = 10

In Odoo domain filter, it will be written as:

syntax : Each tuple in the domain has three fields -> ('field_name', 'operator', value)

field_name : a valid name of field of the object model or in the database table

operator : valid operators are =, !=, >, >=,
value : a valid value to compare with the values of field_name, depending on its type.

ie, domain = [('field1','=',10)] # where field1 should be a field in the model and 10 will be the value

or domain = [('field1','=',field2)] # where field1 and field2 should be the fields in the model



Condition AND

Simple condition in programming:

if field1 = 5 and field2 = 10



In Odoo domain filter, it will be written as:

ie, domain = [('field1','=',5),('field2','=',10)]

or domain = [('field1','=',field3),('field1','=',field3)]



Note : Note that if you don't specify any condition at the beginning and condition will be applied.



Condition OR

Simple condition in programming:

if field1 = 5 or field2 = 10

In Odoo domain filter, it will be written as:

ie, domain = ['|', ('field1','=',5),('field2','=',10)]

or domain = ['|', ('field1','=',field3),('field1','=',field3)]



Multiple Condition

Simple condition in programming:

if field1 = 5 or (field2 ! = 10 and field3 = 12)

In Odoo domain filter, it will be written as:



domain = ['|',('field1','=',5),('&',('field2','!=',10),('field3','=','12'))


Avatar
Discard

Sorry but I don't really get why you're self-asking and answering questions that have been asked and answered dozens of times before already. It also looks ridiculously similar to https://www.odoo.com/nl_NL/forum/help-1/understanding-openerp-domain-filter-58405.

Author

Hi Yenthe,

I thought sharing my old knowledge base with the community was a good idea.

My goal is not to draw attention to myself or to take credit for anything, but just to share.

Even if some of the proposed solutions are now obsolete, they were used at one time for a version of openERP or Odoo. It can still be used for an old version. It's true that I didn't check if the information was already in the forum.

Best Answer

Yanthee This link no longer works

Avatar
Discard

he mistakenly added "." at the end of the url

Related Posts Replies Views Activity
2
Mar 23
3095
3
Jan 24
13378
1
Oct 22
11476
0
May 21
14
2
Nov 24
160