Creating Search VIew Odoo 8

Greetings Everyone,

In this blog-post tutorial, you will learn how to create a Search View in an Odoo 8 module.

What is Search View in Odoo?

  • A search view defines the search options that will be available in the views.

Which search options are available in Search View?

  • Define the ‘fields’ to be searched when a user types in the search box.
  • Set Predefined Filters.
  • Data Grouping options.

Example of a Search View :-

Earlier in my previous blog-post, I had created a Model to collect student’s information. Then I had created its From View and Tree View. Now I will create a Search View for the student model.

Code for creating a Search View

<!-- Search View for Student Information -->
		<record id="student_search_view" model="ir.ui.view">
			<field name="name">student.search.view</field>
			<field name="model">student.student</field>
			<field name="arch" type="xml">
				<search string="Student Information">
					<field name="name"/>
					<field name="email"/>
					<field name="contact"/>
					<group expand="0" string="Group By">
						<filter name="groupby_course" string="Course" domain="[]" context="{'group_by':'course_id'}"
							help="Group Students Course Wise"/>
						<filter name="groupby_year" context="{'group_by': 'registration_date:year'}" string="Year"
							help="Group Students by Year" />
						<filter name="groupby_month" context="{'group_by': 'registration_date:month'}" string="Month"/>
					</group>
					<filter name="fil_by_disability" string="Physically Disabled" domain="[('is_physically_disabled','=','True')]"
						help="Show all Physically Disabled Students" />
					<filter string="Registered Current Year" name="fil_by_current_year" domain="[('registration_date','&lt;=',
						time.strftime('%%Y-12-31')),('registration_date','&gt;=',time.strftime('%%Y-01-01'))]"
						help="Filter Students Registered in Current Year"/>
				</search>
			</field>
		</record>

 

Steps for creating Search View in Odoo

  • Add all the fields that you want to search when a user types in the search box. Here, I have added ‘name’, ’email’, ‘contact’ as searchable fields.
  • To add a Group By filter, add the field as a value in the ‘context’ dictionary with key ‘group_by’. Here, I have added Group by for ‘Course’, ‘Year’ and ‘Month’ .
  • To add a Domain Filter, add your domain in the ‘domain’ attribute. Here, I have added Domain Filter for ‘Physically Disabled’ and ‘Current Year’. By seeing the code you will come to know how to write your own domain.

SnapShot of Eclipse IDE:-

Search View Code Odoo 8
Search View Code Odoo 8 – Click to Enlarge

 

Search Box Odoo 8
Search Box Odoo 8

 

Group By and Domain Filters Odoo 8
Group By and Domain Filters Odoo 8 – Click to Enlarge

 

Hope you learnt how to create a Search View in Odoo module in this tutorial, your reviews/comments/suggestions/doubts are most welcomed, please comment in the section below, and subscribe to the newsletter to receive timely future updates of this blog.

Thank You.

By Burhan Vakharia

Having 6+ years of experience working on Odoo with projects covering several business verticles like Retail industry, Manufacturing, Service, Rental, Education, Medical and many more. I am having experience working on Odoo projects from several countries across the globe.

Leave a Reply

Your email address will not be published. Required fields are marked *