Context

        A context is a python dictionary which is used to pass certain data to the method. We can pass any kind of data/information in context as per the need either from XML or from python and then based on that extra information you can write your process code.


Here are some examples of using context in Odoo,


1. Passing default values for fields


Here, set a default value ‘True’ for the field ‘display_patrner’




2. Context in button



3. Context in search view filters.


In search view, context is using for setting a default filter and group by records.




4. Context in window actions


In window actions, context is using for setting default values for new records.






Domain

        A domain is a condition which is used to filter or search records in Odoo. Each condition in a domain must contain the following three parameters.

Syntax

 [(field_name, 'operator', ‘value’)]


Example

 domain = "[('active', '=', True)]"


Here in the example, field_name is 'active', operator is '=' and value is 'True'


Following are the different types of operators are using in Odoo :


  • Comparison Operators :

    < , >, =, !=, <=, >=

    Example

domain = [('amount', '<', 100.0)]
domain = [('amount', '>', 100.0)]
domain = [('amount', '=', 100.0)]
domain = [('amount', '!=', 100.0)]
domain = [('amount', '<=', 100.0)]
domain = [('amount', '>=', 100.0)]


'like’ Operator:

This operator returns the exact case sensitive search.

Example

domain="[('name', 'like', ‘name’)]"


  • ‘ilike’ Operator:


    This operator returns results matched with case insensitive search.

Example

domain="[('name', 'ilike', ‘name’)]"


  • ‘in’ and ‘not in’ Operators:


    These operators are used to check whether the value is present or not.


Example

domain="[('type', 'in', ('in_invoice'))]

  • domain="[('type', 'not in', ('in_invoice'))]

    child_of’ Operator:
    This operator will search for records who are children of a given record.

Example

domain="[('partner_id', 'child_of', self)]


  • 1. Domain in fields


Python



XML



2. Domain in the search view filter




3. Domain in window action




4. Domain in record rule




If you wish to have the latest updates from us, you may follow us on