How to Inherit or Modify a Search View in Odoo

A search view is a view that helps you search for records in your database. It displays a list of records that match your search criteria, and you can use it to find information quickly and easily.

In Odoo, you can inherit a search view from another view, which is a great way to create a search view that is customized to your needs.

Inheriting a search view is simple in Odoo. You just need to create a new module and inherit the desired search view. Let’s say we want to inherit the invoice and sale order search view to add One2many field search.

<!--Inherit Invoice Search -->
<record id="account_invoice_search_extended" model="ir.ui.view">
    <field name="name">account.invoice.inherit.search</field>
    <field name="model">account.invoice</field>
    <field name="inherit_id" ref="account.view_account_invoice_filter"/>
    <field name="arch" type="xml">
        <xpath expr="//field[@name='number']" position="replace">
            <field name="number" string="Invoice" context="{'active_test': False}" filter_domain="['|','|','|','|',
            ('number','ilike',self), ('origin','ilike',self), ('reference', 'ilike', self), ('partner_id', 'child_of', self),
            ('invoice_line_ids.name','ilike',self)
            ]"/>
        </xpath>
    </field>
</record>
<!--Inherit Sales Search -->
<record id="sale_order_search_extended" model="ir.ui.view">
    <field name="name">sale.order.inherit.search</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.sale_order_view_search_inherit_quotation"/>
    <field name="arch" type="xml">
        <xpath expr="//field[@name='name']" position="replace">
            <field name="name" string="Sales Order" filter_domain="['|','|','|',
            ('name','ilike',self),('client_order_ref','ilike',self),('partner_id','child_of',self),
            ('order_line.name','ilike',self)
            ]"/>
        </xpath>
    </field>
</record>