Chapter 6 - Odoo 15 Development Book

Search view

There are different types of views in odoo, In compared to other views search view is different. Because the search view will not display the whole contents. It is used to filter the contents in other views and not in the form view, because form views consist of a single record.

For example:

<record id="hospital_patient_search" model="ir.ui.view">
  <field name="name">hospital.patient.search</field>
  <field name="model">hospital.patient</field>
  <field name="arch" type="xml">
    <search>
      <field name="partner_name"/>
      <field name="partner_email"/>
      <field name="age"/>
      <field name="gender"/>
    </search>
  </field>
</record>

Here is a search view for the model hospital.patient model. In search view search is the root tag. Here added the 4 fields for searching, based on this field you get the results

Odoo Development Book

Filters and Group By:

n the search view you have filters and groups by. Filter is used to filter the records based on the conditions and group by is used to group the records by a field. You don’t want to choose “Add Custom Filter” or “Add Custom Group” all the time , there is an easy way for adding these by default.

Filter is added by using filter tag inside the search tag. For eg:

<filter string="Archived" name="active" domain="[('active', '=',False)]"/>
Odoo Development Book

When clicking the archived filter, you will get all the archived records. You can give different conditions for filtering in the domain attribute.

In case of group by, you can add the filters inside the group tag, it is also inside the search tag. i.e.,

<group expand="0" string="Group By">
  <filter string="Gender" name="gender" context="{'group_by': 'gender'}"/>
</group> 
Odoo Development Book

Here applying group by for gender. The records will be grouped based on gender field. Using context to pass the data for grouping. The attribute name is required and you can use other fields also for group by filter.

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