Tuesday 29 September 2015

Domain in Odoo

In this article, we will see some theory of domain.

A domain is a list of criteria, each criteria being a triple (either a list or a tuple) of (field_name, operator, value).

Where,

 - field_name:

         It's string type and must be from the current model or any relational traversal field through the Many2one field using membership (.) dot operator.

 - operator:

         It's for comparing field's value with passed value.
Valid operator list (>, >=, <, <=, =, !=, =?, ilike, like =like, =ilike, not like, not ilike, childs_of, in, not in)

 - value:

         It's for comparing with field's value.

Multiple criteria can be joined with three logical operators. Logical AND, logical OR, logical NOT.

Let's take a real inputs example:

Suppose we have 10 records like:

Record 1: Openerp

Record 2: openerp

Record 3: Opensource

Record 4: opensource

Record 5: Open

Record 6: open

Record 7: Odoo

Record 8: odoo

Record 9: Odooopenerp

Record 10: OdooOpenerp

OUTPUT:

'like':

[('input', 'like', 'open')] -  Returns case sensitive (wildcards - '%open%') search.

O/p: open, opensource, openerp, Odooopenerp

'not like':

[('input', 'not like', 'open')] -  Returns results not matched with case sensitive (wildcards - '%open%') search.

O/p: Openerp, Opensource, Open, Odoo, odoo, OdooOpenerp

'=like':

[('name', '=like', 'open')] - Returns exact (=  'open') case sensitive search.

O/p: open

'ilike':


[('name', 'ilike', 'open')] - Returns exact case insensitive (wildcards - '%open%') search.

O/p: Openerp, openerp, Opensource, opensource, Open, open, Odooopenerp, OdooOpenerp

'not ilike': [('name', 'not ilike', 'open')] - Returns results not matched with exact case insensitive (wildcards - '%open%') search.

O/p: Odoo, odoo

'=ilike':

[('name', '=ilike', 'open')] - Returns exact (=  'open' or 'Open') case insensitive search.

O/p: Open, open

'=?': 

name = 'odoo'
parent_id = False
[('name', 'like', name), ('parent_id', '=?', parent_id)] - Returns name domain result & True

name = 'odoo'
parent_id = 'openerp'
[('name', 'like', name), ('parent_id', '=?', parent_id)] - Returns name domain result & parent_id domain result

'=?' is a short-circuit that makes the term TRUE if right is None or False, '=?' behaves like '=' in other cases

'in':

[('value1', 'in', ['value1', 'value2'])] - in operator will check the value1 is present or not in list of right term

'not in':

[('value1', 'not in', ['value2'])] - not in operator will check the value1 is not present in list of right term
While these 'in' and 'not in' works with list/tuple of values, the latter
'=' and '!=' works with string

'=':

value = 10
[('value','=',value)] - term left side has 10 in db and term right our value 10 will match

'!=':


value = 15
[('value','!=',value)] - term left side has 10 in db and term right our value 10 will not match

'child_of':


parent_id = '1' #Agrolait
'child_of':
[('partner_id', 'child_of', parent_id)]
- return left and right list of partner_id for given parent_id

'<=', '<', '>', '>=':

These operators are largely used in openerp for comparing dates - [('date', '>=', date_begin), ('date', '<=', date_end)]. You can use these operators to compare int or float also.



For details/reference visit domains in Odoo

I hope you like this article. Share your views to improve content. Happy Learning !!!

No comments:

Post a Comment

ImportError: cannot import name 'utils' from 'PyPDF2'

Odoo 15: Traceback (most recent call last):   File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner     self...