Enable Dark Mode!
how-to-create-a-search-or-filter-view-in-odoo-19.jpg
By: Safa KB

How to Create a Search Or Filter View in Odoo 19

Technical Odoo 19 Odoo Enterprises Odoo Community

In Odoo 19, there are several view types, including Form, Kanban, List, Calendar, QWeb, and Search. Unlike other views, ‘Search view’ does not display records directly; instead, they are used to filter and refine the data shown in other views. Since Form views display a single record at a time, they do not require a Search view.

How to Create a Search Or Filter View in Odoo 19-cybrosys

In Odoo 19, the highlighted section represents the Search View. Within this view, we can specify the fields that should be searchable. When a user performs a search, Odoo will return results based on the defined field names. Just like Form, List, and Kanban views, a Search View can also be defined in an XML file placed inside the module’s views directory.

For instance, consider the model salon.service, for which we have already created both List and Form views. Next, we can define a Search View for the same model (salon.service) to enable filtering and searching functionality.

salon_service_views.xml

<record id="salon_service_view_search" model="ir.ui.view">
   <field name="name">salon.service.view.search</field>
   <field name="model">salon.service</field>
   <field name="arch" type="xml">
       <search>
           <field name="name" string="Service Name"/>
           <field name="price" string="Price"/>
           <field name="time_taken" string="Duration"/>
       </search>
   </field>
</record>

All search views in Odoo 19 are defined within the <search> tag. In this example, we have included the fields name, price and time_taken as searchable fields. When a user performs a search, Odoo will display the matching results based on these fields. After adding the search view, we can upgrade the module to apply the changes and view the results.

How to Create a Search Or Filter View in Odoo 19-cybrosys

We get the search result based on these field names.

How to Create a Search Or Filter View in Odoo 19-cybrosys

Here we searched the results based on the name. And we have only one record with this name.

Filters and Group By Options

In the Search View of Odoo 19, we can also use the Filters and Group By features. These allow us to filter records or group them based on the fields of the corresponding model. When you click these options, Odoo displays the available filters and grouping options for the model. However, repeatedly selecting Add Custom Filter or Add Custom Group can sometimes be inconvenient.

Filters:

How to Create a Search Or Filter View in Odoo 19-cybrosys

We have an easy way of adding filters by default. We can check how we can do this.

<record id="salon_service_view_search" model="ir.ui.view">
   <field name="name">salon.service.view.search</field>
   <field name="model">salon.service</field>
   <field name="arch" type="xml">
       <search>
           <field name="name" string="Service Name"/>
           <field name="price" string="Price"/>
           <field name="time_taken" string="Duration"/>
             <separator/>
           <filter name="high_price" string="High Price Services"
                   domain="[('price', '&gt;', 100)]"/>
           <filter name="quick_services" string="Quick Services"
                   domain="[('time_taken', '&lt;=', 1.0)]"/>
       </search>
   </field>
</record>

Here we have added a filter for getting records.

How to Create a Search Or Filter View in Odoo 19-cybrosys

Group By:

In the case of Group By, we can give the filters inside the group tag.

How to Create a Search Or Filter View in Odoo 19-cybrosys

From the code, we use a group by currency, and we use context to pass the data. Here, the name is required, and grouping is done by the currency field. We can use any field names of the corresponding model for grouping.

<record id="salon_service_view_search" model="ir.ui.view">
   <field name="name">salon.service.view.search</field>
   <field name="model">salon.service</field>
   <field name="arch" type="xml">
       <search>
           <field name="name" string="Service Name"/>
           <field name="price" string="Price"/>
           <field name="time_taken" string="Duration"/>
             <separator/>
           <filter name="high_price" string="High Price Services"
                   domain="[('price', '&gt;', 100)]"/>
           <filter name="quick_services"  string="Quick Services"
                   domain="[('time_taken', '&lt;=', 1.0)]" />
             <group name="groupby">
               <filter name="group_by_currency" string="Currency"
                       context="{'group_by': 'currency_id'}"/>
           </group>
       </search>
   </field>
</record>

This is the result for the group by currency. Inside the currency group, we can see all the currency records. This way, we can add other fields also for grouping.

How to Create a Search Or Filter View in Odoo 19-cybrosys

Search Views in Odoo 19, along with Filters and Group By options, make it easier to locate, organize, and analyze records efficiently. Defining them properly ensures smoother navigation and faster access to the right data.

To read more about How to Create a Search Panel in Odoo 19, refer to our blog How to Create a Search Panel in Odoo 19.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message