Learn to Customize Search Views in Odoo
This Odoo development video covers one of the most common Odoo customization requests... customizing Odoo search views in one of the most effective ways to increase application usability and better fit Odoo with existing business requirements.
Learn to customize Odoo's powerful search capabilities
Understanding Odoo's search view architecture
Essential Odoo customization to meet business requirements
Customizing Search Views in Odoo v8
What are search views in Odoo?
Whenever you are on a tree view, kanban view, or other view that can be searched Odoo uses an XML Search View definition to determine exactly how the search in Odoo should function for that specific model. For example, in the Sales Order tree view there are specfic options that will help you in locating a sales order in Odoo.
Here we can see how you have options to search by customer, salesperson, sales team, contract, or product. You can also see as we have expanded the search options that we have filters to restrict sales orders to only my sales orders, quotations, sales, To Invoice, Done, and New Mail. The Group By options that are available are also defined in the search view as well.
Do I have to know how to develop modules to customize search views?
This depends on exactly what you wish to do with your search views. Fortunately it is very easy to add extra fields you may wish to search for or remove options that are not appropriate for your specific business requirements. If however you wish to create specialized searches that are more complex it is possible you may need to write custom python code to meet your objects. Most often however you can accomplish most tasks by modifying the search views without the necessity of creating a module.
What is the basic format of a search view in Odoo?
Search views are stored in XML and are quite readable for someone with basic knoweldge of XML. Below is the basic search view:
<?xml version="1.0"?> <search string="Search Sales Order"> <field name="name" string="Sales Order" filter_domain="['|',('name','ilike',self),('client_order_ref','ilike',self)]"/> <field name="partner_id" operator="child_of"/> <field name="user_id"/> <field name="section_id" string="Sales Team" groups="base.group_multi_salesteams"/> <field name="project_id"/> <field name="product_id"/> <filter string="My" domain="[('user_id','=',uid)]" name="my_sale_orders_filter"/> <separator/> <filter string="Quotations" name="draft" domain="[('state','in',('draft','sent'))]" help="Sales Order that haven't yet been confirmed"/> <filter string="Sales" name="sales" domain="[('state','in',('manual','progress'))]"/> <filter string="To Invoice" domain="[('state','=','manual')]" help="Sales Order ready to be invoiced"/> <filter string="Done" domain="[('state','=','done')]" help="Sales Order done"/> <separator/> <filter string="New Mail" name="message_unread" domain="[('message_unread','=',True)]"/> <group expand="0" string="Group By"> <filter string="Salesperson" domain="[]" context="{'group_by':'user_id'}"/> <filter string="Customer" domain="[]" context="{'group_by':'partner_id'}"/> <filter string="Order Month" domain="[]" context="{'group_by':'date_order'}"/> </group> </search>
Each element tells the Odoo engine exactly what options are available in the search.
Why would I want to modify the search views in Odoo?
As the number of records grow within your system, your users will spend more and more time finding the records they need to complete a given task. When you only have a few dozens sales orders in the system then locating data is not a problem. But as the data grows having search functions that make it easy for users to find records becomes more critical. Perhaps more than any other customization option within Odoo, the abiltity to customize search views has perhaps the greatest potential to improve user satisfaction and safe time in using the system.
What will I learn in this video?
In this video we demonstrate how to customize search views in several ways. We start with the basics of adding fields to the list of searchable fields and defining new search criteria. Next we begin to look at how default filters work and how domains within an action can effect the results of your search view. We look into the use of separators to create AND and OR options within your search views. Finally we look at a more complete example from scratch... adding an entirely new field to the model then including that in a customized search view.