Friday, 12 January 2018

How to create a Search and Calendar Views in Odoo?

Hello dear fellow. In this article, we will learn how to create a Search and Calendar views in Odoo?

Search view is declared quite similarly to a form view, except that the view type and root element change to search instead of form, they are used to filter other view’s content, generally lists or graphs views.

Let’s take an example :

We have a model named Marks which has a Many2one fields called ‘student_id’ ‘course_id’ and four float fields ‘exam1’ ‘exam2’ ‘extrat’ and ‘average’.
So Marks search view looks like this:












Explanation

Here we have added ‘student_id’ as searchable field, and course_id as a group by filter,

Context : Search a python dictionary, merged into the action’s domain to generate the search domain. The context passed to the data view for searching and filtering.
Filter : Adding data to the search context .

Implementation

1. Search Box in Odoo9























2. Group by filters in Odoo9























When opening your list view, you’ll  notice the search field to the upper right. If you type something there, you get suggestions about what to search for and there is also a set of predefined filters to choose form.


Calendar Views

Calendar view provides timeline – schedule view for the data, they display records as events in a daily, weekly, or monthly calendar. Their root element is “Calendar”.

Here is an example of Calendar views:


















Note: Don’t forget to add calendar to  view_mode in an action views.

Explanation


  • color : Name of a record field to use for color segmentation.
  • date_start: nome of record’s field holding the start date for the event.

Implementation























Thank You.

Odoo Constrains & Odoo _sql_constraints

Implementing Constrain in Odoo (With Method)

@api.constrains('name')
def validate_email(self):
for obj in self:
if len(obj.name) < 2:
raise ValidationError("Please Provide valid Name: %s" % obj.name)
return True


Implementing sql_constraint in Odoo

_sql_constraints = [
('email_uniq', 'unique(email)', 'Email id is unique change your custom email id'),
('phone_uniq','unique(phone)','Phone number is unique so change your phone number ')
]