Enable Dark Mode!
how-to-add-a-field-to-the-existing-search-panel-in-odoo-18.jpg
By: Anfas Faisal K

How to Add a Field to the Existing Search Panel in Odoo 18

Technical Odoo 18

In Odoo 18, the Search Panel is a valuable UI element that allows users to filter records quickly using predefined categories on the left-hand side of the tree or kanban views. If you're customizing the HR module and want to extend the Search Panel with your own field, like an Employee Type, this guide walks you through the process step by step.

In this example, we’ll add a custom employee_type_id field to the existing search panel in the Employees module by:

* Creating a new model: hr.employee.type

* Adding a Many2one field in the hr.employee to link it

* Extending the search panel view to display this new field as a filter

Step-by-Step Guide

Step 1: Define the Employee Type Model

First, we create a new model hr.employee.type which will hold the different employee types (e.g., Intern, Contractor, Permanent).

models/hr_employee_type.py

from odoo import models, fields
class HrEmployee(models.Model):
    _inherit = 'hr.employee'
    employee_type_id = fields.Many2one(
        'hr.employee.type',
        string="Type of Employee",
        help="Select the classification or type of this employee (e.g., Permanent, Contract, Part-time)."
    )

Step 2: Add a New Field to the Employee Model

Now we inherit the hr.employee model and add a new Many2one field pointing to the hr.employee.type model.
models/hr_employee.py
from odoo import models, fields

class HrEmployeeType(models.Model):
    _name = 'hr.employee.type'
    _description = 'Employee Type'
    name = fields.Char(
        string="Employee Type Name",
        required=True,
        help="Enter the name of the employee type (e.g., Full-time, Contractor, Intern)."
    )

Step 3: Grant Access Rights

Create a security file to allow access to the new model.

security/ir.model.access.csv

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_hr_employee_type,access_hr_employee_type,model_hr_employee_type,,1,1,1,1

Step 4: Create Views for Employee Type Model

Define tree and form views so users can manage employee types from the UI.

views/hr_employee_type_views.xml

<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <record id="hr_employee_type_view_tree" model="ir.ui.view">
        <field name="name">hr.employee.type.view.tree</field>
        <field name="model">hr.employee.type</field>
        <field name="arch" type="xml">
            <list>
                <field name="name"/>
            </list>
        </field>
    </record>
    <record id="hr_employee_type_view_form" model="ir.ui.view">
        <field name="name">hr.employee.type.view.form</field>
        <field name="model">hr.employee.type</field>
        <field name="arch" type="xml">
            <form>
                <sheet>
                    <field name="name"/>
                </sheet>
            </form>
        </field>
    </record>
    <record id="action_hr_employee_type" model="ir.actions.act_window">
        <field name="name">Employee Type</field>
        <field name="res_model">hr.employee.type</field>
        <field name="view_mode">list,form</field>
    </record>
    <menuitem id="menu_hr_employee_tag_action"
          name="Employee Type"
          parent="hr_employee_type_menu"
          action="action_hr_employee_type"/>
</odoo>
Screenshot of  Menu Path and Tree View of the Employee Type

How to Add a Field to the Existing Search Panel in Odoo 18-cybrosys

Step 5: Add Custom Field to Employee Form and Search Panel

We now update the employee form view to include the new field and add it to the search panel.

<odoo>
    <menuitem id="hr_employee_type_menu"
              name="Employee Type"
              parent="hr.menu_human_resources_configuration"
              sequence="30"/>
    <record id="view_employee_form" model="ir.ui.view">
        <field name="name">hr.employee.view.form.inherit.search.panel.custom</field>
        <field name="model">hr.employee</field>
        <field name="inherit_id" ref="hr.view_employee_form"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='category_ids']" position="after">
                <field name="employee_type_id"/>
            </xpath>
        </field>
    </record>
    <record id="view_employee_filter" model="ir.ui.view">
        <field name="name">hr.employee.view.search.inherit.search.panel.custom</field>
        <field name="model">hr.employee</field>
        <field name="inherit_id" ref="hr.view_employee_filter"/>
        <field name="arch" type="xml">
            <xpath expr="//searchpanel" position="inside">
                <field name="employee_type_id" icon="fa-tags"/>
            </xpath>
        </field>
    </record>
</odoo>

Screenshot of the Employee Form View 

How to Add a Field to the Existing Search Panel in Odoo 18-cybrosys

Screenshot of the Employee Kanban View Panel

How to Add a Field to the Existing Search Panel in Odoo 18-cybrosys

Screenshot of the Selected Search Panel

How to Add a Field to the Existing Search Panel in Odoo 18-cybrosys

Step 6: Define the Manifest File

Make sure to register all files in the manifest.

{
    'name': 'Search Panel Custom',
    'version': '18.0.1.0.0',
    'category': 'Industries',
    'author': 'Cybrosys Techno Solutions',
    'company': 'Cybrosys Techno Solutions',
    'maintainer': 'Cybrosys Techno Solutions',
    'website': "https://www.cybrosys.com",
    'depends': ['hr'],
     'data': [
        'security/ir.model.access.csv',
         'views/hr_employee_views.xml',
         'views/hr_employee_type_views.xml',
    ],
    'images': ['static/description/banner.jpg'],
    'installable': True,
    'auto_install': False,
    'application': False,
}

Final Result

After installing the module:

* You'll see a new "Type of Employee" field in the Employee form.

* A new menu item under HR > Configuration > Employee Type to manage types.

* In the search panel on the Employee list view, you can filter employees by type.

Screenshot of the Result.

How to Add a Field to the Existing Search Panel in Odoo 18-cybrosys

Conclusion

This module improves the usability of the Employee module by providing more structured categorization and quick filtering through the search panel. It’s a great example of how to use Odoo’s extension mechanisms to enhance user experience with minimal code.

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


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