Professional Documents
Culture Documents
odootricks.tips
Context in Odoo
7-9 minutes
Form Views
Kanban Views
User-defined Filters
This is either:
Group By
Sorting
Record Selection
Set language
1 of 8 2/23/2022, 4:27 AM
Context in Odoo about:reader?url=https%3A%2F%2Fodootricks.tips%2Fabout%2Fbuildi...
{'default_customer':1,'default_is_company': True}
It will always start with {“default_ then the field name and value.
In this case there are two fields:
is_company = True
Customer
Is a company
2 of 8 2/23/2022, 4:27 AM
Context in Odoo about:reader?url=https%3A%2F%2Fodootricks.tips%2Fabout%2Fbuildi...
Views.
For example, if you create a new tax in the Sales app it should be
a sales tax:
Note that the 2nd parameter is a field name rather than a constant.
Of course, you can have defaults for multiple fields, and in this
example we default both the the customer and the sales order
number (again, it’s to create an Analytic Account):
Note that these are defaults, so users can make changes (though
sometimes the field may be read-only or invisible, in which case
they can’t).
Filters
Note: Record Rules and domain can also restrict what records are
3 of 8 2/23/2022, 4:27 AM
Context in Odoo about:reader?url=https%3A%2F%2Fodootricks.tips%2Fabout%2Fbuildi...
A filter will further limit what is displayed, but the user can remove
it.
{'search_default_customer': 1}
This is the filter (note the ‘X’ to show that it can be removed):
If users remove the filter it will display suppliers as well (this might
be useful if a contact has been setup as a supplier and should also
be a customer) but of course the display is still limited by
domain and Record Rules.
This means that the “Customer” filter will be applied (as above).
4 of 8 2/23/2022, 4:27 AM
Context in Odoo about:reader?url=https%3A%2F%2Fodootricks.tips%2Fabout%2Fbuildi...
Group By
Expand
'expand': 1
Sort order
This allows the initial sort order to be set for a List View or Kanban
View
{'show_sale': True,
'search_default_order_confirmed': 1}
XML syntax for sorting (for reference – does not use Context):
As standard, Odoo will only display active records from a table, but
it’s possible to override this.
We can see this in the menu option for Currencies. This is the
Windows Action for Accounting / Configuration / Currencies:
5 of 8 2/23/2022, 4:27 AM
Context in Odoo about:reader?url=https%3A%2F%2Fodootricks.tips%2Fabout%2Fbuildi...
Filter ON
It’s easy to see which currencies are inactive because they appear
after the active currencies and in a grey font:
This is because Odoo comes with all currencies already setup and
you should activate rather than create.
It’s used for currency selection, and also on the Product Template
for a service item (if Project Management is installed):
6 of 8 2/23/2022, 4:27 AM
Context in Odoo about:reader?url=https%3A%2F%2Fodootricks.tips%2Fabout%2Fbuildi...
Record Selection
7 of 8 2/23/2022, 4:27 AM
Context in Odoo about:reader?url=https%3A%2F%2Fodootricks.tips%2Fabout%2Fbuildi...
However, it’s easier to use domain for this, and that is what you will
usually find in Odoo.
Set language
{'lang': 'fr_FR'}
<xpath expr="//field[@name='order_line']"
position="attributes">
<attribute name="context">{'lang': 'fr_FR'}
</attribute>
</xpath>
OR
8 of 8 2/23/2022, 4:27 AM