In Odoo 16, the SearchPanel is a powerful tool for filtering records within list, kanban, and other views. You can configure its default state to define which filters or groups are shown by default when the view is loaded.
Here’s how you can configure the default state of the SearchPanel in Odoo 16:
1. XML View Definition
You can configure the SearchPanel in the view’s XML file using the search_panel
tag within the search
view. The default state involves specifying which fields are pre-filtered or shown in the Search Panel when a view is initially opened.
2. Basic Example for SearchPanel Configuration:
<record id="view_your_model_tree" model="ir.ui.view">
<field name="name">your.model.tree</field>
<field name="model">your.model</field>
<field name="arch" type="xml">
<tree>
<!-- Define your tree structure here -->
</tree>
<search>
<search_panel>
<!-- Filter on a many2one field -->
<field name="your_many2one_field"
string="Category"
default_group_by="True" />
<!-- Filter on a date field -->
<field name="your_date_field"
string="Date"
filter="day"
default_filter="this_month" />
</search_panel>
</search>
</field>
</record>
Key Attributes in the SearchPanel:
- default_group_by: Defines if the records should be grouped by this field by default.
- default_filter: Specifies a default filter, especially for date fields (e.g.,
"this_month"
,"today"
, etc.).
3. Default State Filters:
You can set default filters for specific fields, especially date filters. Here’s an example where we set a default filter on a date field:
<search_panel>
<field name="your_date_field"
string="Creation Date"
filter="day"
default_filter="today"/>
</search_panel>
4. Full Example:
In this example, we have both a many2one
field filter and a date
field filter, and they are both configured with default values.
<record id="view_your_model_tree" model="ir.ui.view">
<field name="name">your.model.tree</field>
<field name="model">your.model</field>
<field name="arch" type="xml">
<tree>
<!-- Tree structure -->
</tree>
<search>
<search_panel>
<field name="category_id"
string="Category"
default_group_by="True" />
<field name="create_date"
string="Creation Date"
filter="day"
default_filter="this_week" />
</search_panel>
</search>
</field>
</record>
5. Available Filters:
For date fields, you can set default filters like:
"today"
"yesterday"
"this_week"
"this_month"
"this_year"
Conclusion
While using Odoo 16, the SearchPanel is one of the most robust tool for filtering all records inside the specific list, kanban, and some other views. You can easily setup its default state to describe which groups or filters are displayed on the screen by default. Here are some above-mentioned steps that helps you to setup of the SearchPanel in the case of Odoo with managed odoo server solutions.