Adding fields to quick search views

Hi guys,

In this tutorial I will teach you how to add fields to existing quick search options. In this tutorial I will add the reference field from a quotation / order to the quick search view so that you can quick search on it. An example of the result after this tutorial:
Quick search example

1. Inheriting the search view

The first thing to do is to find the search view where you want to add your own fields in. The easiest way to do this is to activate developer mode in Odoo, opening up the developer icon and by clicking on ‘Edit SearchView’:
Edit searchview

After you’ve clicked on this menuitem a dialog will pop-up where you can find all the details from the view. Now search for the field ‘External ID’ and copy the value from this field:
View id
This value is the ID to this search view, which you will need to inherit in order to add your custom field in it later on.
In my example the ID of this view is ‘sale.sale_order_view_search_inherit_quotation’.

Now open up (or create) an XML file and inherit the existing search view like this:

What exactly does this code do? The record id will be the unique id for this view in the database and the model ‘ir.ui.view’ tells Odoo that it is a view. In the field name=”name” tag you should add an unique name for the record. The model refers to the model of the view you’re working on (in this tutorial sale.order) and the inherit_id field refers to the view from which we just copied the ‘External ID’.
Next we’ll add an arch field in which we will later on add the field we want to quick search on.

Adding your own field(s) to the quick search

Alright, you’ve now inherited the view. The only thing left to do now is to add the fields on which you want to quick search. In this example I’ll add the reference field from a quotation/order. In order to add the field in the search you should xpath in to the search element of the view to add your field in it. So you’ll do an xpath on the view with a position=”inside”. Inside this xpath expression you can then add the field(s) you’d like. Your code should look like this:

That is all! When you install this module you’ll see the field you’ve just added show up in the quick search dropdown. In my example it’ll look like this:
Quick search result

3. Conclusion

Inheriting and expanding quick search views is really easy to do in Odoo and it is very powerful. You can simply inherit the view, xpath in to the search part and add all the fields that you’d like to search on.

Do you want to try the demo code and see the source code of this tutorial? You can view it on my Github account.
Has this tutorial helped you, do you have any feedback or questions? Post away!




PayPal

Odoo Experts