How to Create a Cohort View in Odoo 18: Complete Step by Step Guide
By Braincuber Team
Published on March 31, 2026
Odoo offers a variety of views such as list, form, tree, kanban, graph, pivot, calendar, and cohort. Among these, the cohort view is a powerful reporting tool used to analyze and track user behavior over time. It organizes data into rows and columns, where each cell represents a specific metric for a cohort during a given time period. This complete tutorial will guide you through creating a cohort view in Odoo 18 from scratch.
What You'll Learn:
- What a cohort view is and how it helps analyze data trends over time
- How to define a model with the necessary fields for cohort analysis
- Setting up access rights and security rules for the custom model
- Configuring the web_cohort dependency in the manifest file
- Creating XML views for tree, form, and cohort view modes
- Understanding cohort view attributes: date_start, date_stop, interval, and mode
Understanding the Cohort View in Odoo 18
The cohort view makes it easy to see changes and trends daily, weekly, monthly, or yearly. It is particularly useful for tracking retention, churn, and engagement metrics across different time periods. To create a cohort view in Odoo, you need to define a model and a view with specific date fields that the cohort view uses to calculate time-based groupings.
| View Type | Purpose | Best For |
|---|---|---|
| Cohort | Track behavior over time periods | Retention, churn, engagement analysis |
| Pivot | Multi-dimensional data analysis | Cross-tabulation and aggregation |
| Graph | Visual data representation | Charts, trends, and comparisons |
| Kanban | Card-based visual management | Workflow stages and task management |
Step 1: Creating the Model with Required Fields
To create a cohort view in Odoo, you first need to define a model with the necessary fields. In this example, we'll add a new model to the Employee module and create a menu item under the Configuration tab.
Create the Python Model File
Create a new class called EmployeeDetails that allows selecting employees from the hr.employee model.
Add Related Fields
Set phone and email as related fields so they automatically populate when an employee is selected.
Add Required Date Field
Add a required date field that will be used as the date_stop in the cohort view configuration.
# -*- coding: utf-8 -*-
from odoo import models, fields
class EmployeeDetails(models.Model):
_name = 'employee.details'
_description = 'Employee Details'
_rec_name = "employee_id"
employee_id = fields.Many2one('hr.employee', string="Employee")
phone = fields.Char(related="employee_id.work_phone", readonly=True)
email = fields.Char(related="employee_id.work_email", readonly=True)
date = fields.Date(string="Date", required=True)
Related Fields Explained
The phone and email fields are set as related fields, so they will automatically populate when an employee is selected. This eliminates manual data entry and ensures data consistency with the hr.employee model.
Step 2: Setting Up Access Rights
Before creating the cohort view, you need to add access rights for the custom model. Without proper access rights, users will not be able to view or interact with the model data.
Create Security Directory
Create a new directory called security with a CSV file for security settings in your module.
Define Access Rule
In the CSV file, define the ID, name, model ID, group ID, and permission flags for read, write, create, and unlink operations.
Register in Manifest
Include the security file in the module's __manifest__.py under the data section.
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_employee_details,access.employee.details,model_employee_details,base.group_user,1,1,1,1
Permission Flags Explained
The four permission flags at the end represent: perm_read (view records), perm_write (edit records), perm_create (create new records), and perm_unlink (delete records). Setting all to 1 grants full access to base.group_user (all internal users).
Step 3: Adding web_cohort Dependency
Before creating the cohort view, make sure to add web_cohort as a dependency in the __manifest__.py file. This module provides the cohort view functionality and must be installed for the view to work.
{
'name': 'Employee Cohort View',
'version': '18.0.1.0.0',
'category': 'Human Resources',
'depends': ['hr', 'web_cohort'],
'data': [
'security/ir.model.access.csv',
'views/employee_details_views.xml',
],
'installable': True,
'auto_install': False,
'application': False,
}
The web_cohort module is essential for cohort view functionality. Without it, the cohort view mode will not be recognized by Odoo and the view will fail to render. Make sure it's listed in the depends array alongside any other modules your custom module requires.
Step 4: Creating the Window Action
Next, create an XML file to define the view. Start by creating an ir.actions.act_window record for the employee.details model. In this action, specify the view modes you need — for example, tree, form, and cohort.
Employee Details
employee.details
ir.actions.act_window
list,form,cohort
Assign it an ID like employee_details_action_menu, which will be used to link this action to a menu item. The view_mode field specifies which view types are available when accessing this model. Include cohort to enable the cohort view alongside list and form views.
Step 5: Defining the Cohort View
Now let's create the cohort view. Start by defining a record with a unique ID and set the model to ir.ui.view. The cohort view requires specific date fields and configuration attributes to function correctly.
Set date_start
Use create_date as the date_start — this is the built-in timestamp when each record was created.
Set date_stop
Use the date field from your model as the date_stop for cohort period calculation.
Configure Interval and Mode
Set the interval to day, week, month, or year and the mode to churn or retention.
employee.details.view.cohort
employee.details
| Attribute | Description | Example Values |
|---|---|---|
| date_start | The starting date field for cohort grouping | create_date, date_order, start_date |
| date_stop | The ending date field for period calculation | date, close_date, end_date |
| interval | Time granularity for cohort periods | day, week, month, year |
| mode | Analysis type for the cohort data | churn, retention |
Churn vs Retention Mode
Churn mode shows the percentage of records that left or stopped during each period. Retention mode shows the percentage of records that remained active. Choose the mode that best fits your analysis goal.
Step 6: Creating the Menu Item
Finally, create a menu item for the model. In the menuitem tag, set the action to the ID of the record you defined earlier, and specify the parent to indicate where the menu should appear in the menu structure.
The menu item is placed under hr.menu_config_employee (the Configuration tab in the Employee module) with a sequence of 20. You can change the parent to any existing menu in Odoo to place your cohort view wherever it makes the most sense for your workflow.
Using the Cohort View in Odoo 18
After installing the module, go to the Employee module. You'll find the Employee Details menu under the Configuration tab. Clicking the menu will open the model in a tree view, where you can add and manage records.
List View
Multiple records can be added and managed in the list view. This is the default view when opening the menu.
Cohort View
Click the cohort view icon to see a day-wise report of the records directly in the UI with color-coded cells.
Switching Between Views
You can see the list and cohort view icons in the top-right corner of the view. Click the cohort view icon to switch from list view to the cohort visualization. The view will display records organized by their creation date and the custom date field.
Frequently Asked Questions
What is a cohort view used for in Odoo?
A cohort view analyzes and tracks user behavior over time by organizing data into rows and columns. Each cell represents a specific metric for a cohort during a given time period, making it easy to see trends daily, weekly, monthly, or yearly.
Why is web_cohort required for cohort views?
The web_cohort module provides the JavaScript components and rendering logic for the cohort view. Without it, Odoo will not recognize the cohort view mode and the view will fail to load.
What is the difference between churn and retention mode?
Churn mode shows the percentage of records that left or stopped during each period, while retention mode shows the percentage that remained active. Choose based on whether you want to track losses or continued engagement.
Can I use create_date as date_start?
Yes, create_date is a built-in field automatically added to all Odoo models. It records when each record was created and is commonly used as the date_start for cohort analysis.
What intervals are available for cohort views?
The available intervals are day, week, month, and year. The interval determines how the cohort periods are grouped in the visualization. Choose the interval that best matches your analysis timeframe.
Need Help with Odoo Reporting?
Our experts can help you implement cohort views, build custom reports, and optimize your Odoo 18 analytics for better business insights and decision-making.
