Globalteckz is one of the leading Odoo integrators and ERP service providers in India, offering expert solutions in Odoo, ERPNext, and business automation for startups and enterprises. With a skilled team, we deliver customized ERP implementation, integration, and support services to streamline operations and drive digital transformation across India, UAE, USA, Canada, and the UK.
Mira Road Location: Unit 002, Building A7, Sector 5, Mira Road (East), Thane, Mumbai – 401107.
Call/WhatsApp:
+(91) 9833344333
+(91) 9773530597
Email: sales@globalteckz.com
Teams/Skype
kadriazhar | abraar.patel
Copyright © 2025 | Globalteckz - (India & USA). All rights reserved. | Terms and Conditions
Using Context and Domain in Odoo
How to use context and domain in Odoo ERP | Context in Odoo is a part of the environment of a record set. It is basically a python dictionary that carries the session data. This data can be used on both the client-side user interface and also the ORM business logic in case of server-side. So most importantly we can use the context to pass the specific data to a function in odoo. You may have seen that almost all methods in Odoo use a context parameter. Context is used to pass information such as the time zone or the language of the user interface as well as the contextual parameters specified in the actions in odoo.
What is context in Odoo ERP software :
Context is a dictionary that carries information such as user ID, user language, Timezone, etc. by default. With that one can pass any kind of data or information in context as per the requirements and needs or through xml or from python (methods) files and then based on that extra information can be written to process code.
Let discuss how to use context in Odoo:
A number of methods in the Odoo standard add on’s use the context data to adapt the behavior to these values. It is sometimes necessary to modify the context on a record set to get the desired results from a method call or the desired value for a compute field. You can pass any kind of data or information using context as per your need or requirement either from the XML file or from the python files (method files). So based on that later you can write the process code using the information that you got from the context that you have given.
In the above, it set a default value for company_id
We know window actions are an important part of odoo architecture. Context can be used in window actions to set default values for new records or to display inactive records. An example of context in window actions is given below.
Both the context and domain are particularly useful in relational fields. Default values for related records can be defined using context
In the above example it set a default value for company_id in a many2one field company_id.
You can access the value in python function which is passed in XML file using context as follows.
Suppose you have passed a value partner_id in your XML file, in your python function you can access it as self.env.context.get(‘partner_id’). self.env.context.get() function is used to check whether that key is present in your context. So make sure that your context contains this parameter and also it contains a value.
Inside the group tag, we have added two filters and passed the group_by in the context
What is Domain in Odoo:
Domain is a condition which we used to filter the data or for searching. A domain expression consist of list of conditions. Each condition is a (‘field_name’, ‘operator’, ‘value’) tuple which has been described below
The usual comparison operators are < , > , <= , >= , = , != .
Let discuss how to use Domain in Odoo:
The syntax is as follows:
domain=”[(field_name, ‘operator’, ‘value’)]”
field_name: In this, the field name indicates simply the field name in which you want to assign domain.
Operator: The list of operators used are given below
*Usual comparison operators: < , >, =, !=, <=, >=
*=like’ operator: This operator matches against a pattern. The ‘%’ symbol matches against any sequence of characters. It returns the exact case sensitive search.
Eg: [(‘name’, ‘=like’, ‘odoo’)] – this returns ‘odoo’
*like’ operator: This operator matches against a ‘%value%’ pattern, which is similar to ‘ilike’ operator. It also returns a case sensitive search.
Eg: [(‘name’, ‘=like’, ‘odoo’)] – this returns ‘%odoo%’.
*ilike’ operator: This operator returns exact case insensitive search.
Eg: [(‘name’, ‘=like’, ‘odoo’)] – this returns ‘%Odoo%’, ‘%odoo’
*not like’ and ‘not ilike’ operators: ‘not like’ operator returns result not matched with case sensitive and ‘not ilike’ operator returns result not matched with case insensitive.
*In’ and ‘not in’ operator: These operators are used to check whether the value is present or not present in a list of values.
*child_of’ operator: This operator is used to find children’s values in a hierarchical relation.
Some of the examples of a domain are given below.
2. Using domain in record rule.
Setting domain force in the following example in case employee_id.user_id is user.id
3. Using domain in fields_view_get() method to set dynamic values for domain filters.
4. A domain can also be used to filter relational object fields records with conditions.
5. Using the domain to display specific records based on condition
To Summarize : Therefore, domain is a filter you cannot expand beyond – context is a filter you can expand to the point that domain allows. The above screenshot of the tutorial how to use context and domain in odoo has been taken considering Odoo version 13 for latest version of Odoo ERP somehow the process remains the same. For any further technical questions feel free to contact us on sales@globalteckz.com
About Globalteckz:
At Globalteckz we offer our clients with world class Business and Enterprise solutions. We are presence in India, USA, & Canada, and have successfully offered end to end solutions to our clients. Some of our services offering include leading Open Source Solutions such as Odoo, Magento, and others ecommerce development. We deliver excellence and quality for Information Technology & Software Solutions to our clients worldwide.
For questions on Odoo pricing and cost that can involve with your business you can contact our sales team on sales@globalteckz.com
Read more articles related to Odoo Pricing :