In Odoo 18, the search panel helps users classify data in predefined categories. These categories can be different types of fields, such as Many2One, Many2Many, and selection.
Understanding the Search Panel in Odoo 18
Odoo’s search panel allows users to browse specific filters and move through them directly from the display.
In the above image, there are records of the Order Your Lunch model. On the left side, we can see the search panel. There are two fields: categories and vendors. So we can classify records using these two fields.
Setting Up the Development Environment
Make sure you have your Odoo 18 development setup configured before you start writing code. The basic steps are as follows:
- Install Odoo 18: First, you need to ensure that your server or local computer is operating and has Odoo 18 installed.
- Set Up a Code Editor: Any coding editor, including VS coding and Sublime Text, will work. Make sure your development setup supports Python and XML editing, as these are the primary languages for Odoo development.
- Create a New Custom Module: To add a search panel, you will need to use a custom Odoo module.
Steps to Create Search Panel in Odoo 18
We can set up a search panel for the product model. The following is an example of the XML code for the search panel:
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="product_template_search_panel" model="ir.ui.view">
<field name="name">product.template.search.panel</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_search_view"/>
<field name="arch" type="xml">
<search position="inside">
<searchpanel>
<field name="categ_id" icon="fa-filter" string="Category" select="multi"/>
<field name="type" icon="fa-files-o"/>
</searchpanel>
</search>
</field>
</record>
</odoo>
The product. template model in Odoo has a search panel defined by this XML code. By deriving from an existing search view (product.product_template_search_view) and integrating a search panel that allows product filtering based on category (categ_id) and type (type), it alters the search view.
Additionally, the search panel has icons (fa-filter for category and fa-files-o for type) that visually depict the filters. Multiple categories can be selected simultaneously when using the categ_id select="multi" option.
Here is the output:
Odoo 18 Customization in the Search Panel
By including further fields, arranging filters into groups, or configuring particular filtering parameters, you can further alter the search panel. Here’s a demo of how to add a new field—let's say state—and filter data according to the order status:
XML
<searchpanel>
<field name="partner_id" />
<field name="user_id" />
<field name="state" />
</searchpanel>
Odoo manages these fields automatically, which simplifies the process for users to choose and apply filters from the search panel.
Testing the Search Panel
After finishing the code, restart the Odoo server and update the module list. Install your customized module (Custom search panel Odoo 18 Demo). When you enter the Sales Order module, you should see a search panel on the left side of the page with the fields you specified (customer, salesperson, and order status).
To confirm that the search panel functions correctly, test it with various Dynamic search filters Odoo. If everything is configured successfully, the record should filter in real-time based on the criteria chosen.
Conclusion
For models managing large amounts of data, the Odoo 18 Search Panel is a very helpful feature. By streamlining users’ access to and filtering information through the search panel, you may enhance the user experience overall and make navigation easier.
It’s easy to integrate into your module, and you can customize it to meet your unique needs, thanks to Odoo’s versatility.