Enable Dark Mode!
how-to-use-configure-search-view-filter-group-in-odoo-16.jpg
By: Amaya Aravind EV

How to configure Search View , Filters & Group by in Odoo 16

Technical Odoo 16

There are different view types in Odoo, including Form, Kanban, Tree, Calendar, Qweb, Search,  etc.  In contrast to Form views, Search views are used to filter the contents of other views rather than displaying the content themselves. This makes Search views distinct from other views. There is no need for a search because form views only contain one record.

The Search views and filters in Odoo 16 will be covered in detail in this article.

How to configure Search View & Filters, Group by in Odoo 16-cybrosys

If we search for something that is present in the view, we may add field names to the search and receive results based on the related field name. The process for creating a Search View in Odoo 16 can then be examined. We can add a search view to an XML file inside the views folder, just as Form, Tree, and Kanban views.

Eg; we have already defined the list and form view for this model, school.student, and created a model of it. We can now create a search view for the school.student model.

school_student_views.xml

<record id="school_student_view_search" model="ir.ui.view">
   <field name="name">school.student.view.search.module.name</field>
   <field name="model">school.student</field>
   <field name="arch" type="xml">
       <search>
           <field name="name"/>
           <field name="email"/>
           <field name="age"/>
           <field name="gender"/>
           <field name="active"/>
       </search>
   </field>
</record>

Inside the search tag, we define each search view.  From this point, we named the fields for the search: name, email, age, and gender.

How to configure Search View & Filters, Group by in Odoo 16-cybrosys

We receive all of the search results based on these search variables.

How to configure Search View & Filters, Group by in Odoo 16-cybrosys

Filters and Group By Options:

In the Search window, we also have the options of Filters and Group By. By the fields of the corresponding model, we can filter and group the records. We can view all the filters pertaining to the model if we click on these options. We want to consistently select Add Custom Filter or Add Custom Group. It is sometimes difficult.

How to configure Search View & Filters, Group by in Odoo 16-cybrosysHow to configure Search View & Filters, Group by in Odoo 16-cybrosys

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

<record id="school_student_view_search" model="ir.ui.view">
   <field name="name">school.student.view.search.module.name</field>
   <field name="model">school.student</field>
   <field name="arch" type="xml">
       <search>
           <field name="name"/>
           <field name="email"/>
           <field name="age"/>
           <field name="gender"/>
           <field name="active"/>
           <filter string="Archived" name="active" domain="[('active', '=', False)]"/>
       </search>
   </field>
</record>

To get all archived entries, a filter has been introduced in this instance. If the name is a required element, we can insert any names in this name attribute. Furthermore, since the filter will be based on the domain, the domain name must be given. That is, if the field active is false, the filter will record that fact.

How to configure Search View & Filters, Group by in Odoo 16-cybrosys

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

<record id="school_student_view_search" model="ir.ui.view">
   <field name="name">school.student.view.search.module.name</field>
   <field name="model">school.student</field>
   <field name="arch" type="xml">
       <search>
           <field name="name"/>
           <field name="email"/>
           <field name="age"/>
           <field name="gender"/>
           <field name="active"/>
           <filter string="Archived" name="active" domain="[('active', '=', False)]"/>
           <group expand="0" string="Group By">
               <filter string="Gender" name="gender" context="{'group_by': 'gender'}"/>
           </group>
       </search>
   </field>
</record>

Here, in the code, we are using context for group by gender. So the grouping will be done by gender field. We can use the field for grouping.

How to configure Search View & Filters, Group by in Odoo 16-cybrosys

Like this, we can customize the search view in Odoo 16.


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