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!
Tutorial sponsored by Oocademy


4 thoughts on “Adding fields to quick search views

  1. Dozz says:

    Hi, Yenthe, big thanks for all your sharing contents about Odoo. I’m developing an ERP of my little company for over 1 year. Your article and information do help a lot to me.
    Here I have the same need as what you taught in this topic : In Customer page, I want to add a quick search field : ref ( i.e. Internal Reference ) to the search bar.
    However, I’m not major in IT, thus it’s a little difficult for me to totally understand the steps. ( I’m not so familiar about Python codes. )
    My question is :
    1. How to / Where to “open up (or create) an XML file” ?
    2. Can I finish all the steps in my browser ? (My Odoo is 11.0 community edition) Or do I need to use terminal command lines ?

    Thanks again.

    • Yenthe666 says:

      Hi Dozz,

      Great to hear that my tutorials have helped you! 🙂
      1. You will need to do this in a own folder, which means you’ll make a new module. It should be in the views/ folder.
      2. No you will need to code in the files and do commands from the terminal (such as restart the Odoo service)

      • Dozz says:

        Hi Yenthe, so glad to heard from you.

        Actually, It seems that I figured it out by my own way, and I just added 1 line in the code of search view (without making any new module or something….) :
        1. The added code :
        2. The result works as I want :
        (I even didn’t “restart” the Odoo service, and it works just as well.)

        However, I’m not professional in this, so I don’t know if there will be any bad effect to the system. (Error index or something…). Please give me advice when you’re free.
        Thanks again !!

        • Yenthe666 says:

          Hi Dozz,

          You’re absolutely right that this will work fine too. You’re basically doing the same as my tutorial, just from the frontend and not in the code. The only downside for doing it from the frontend is that at some point you’ll loose track of all the changes you’ve done and it is hard to maintain. If it is in code you can easily find it, manage it and it will always be there.

Leave a Reply