How to Create Cohort View in Odoo 17 - Odoo 17 Slides

CelineGeorge1 783 views 15 slides Aug 05, 2024
Slide 1
Slide 1 of 15
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15

About This Presentation

Odoo has a variety of view kinds, including list, form, tree, kanban, graph, pivot, calendar, cohort, and more. Cohort views are a kind of reporting view in Odoo that let us monitor and evaluate user behavior across time. Rows and columns are displayed in the cohort view.


Slide Content

How to Create Cohort View in Odoo 17 Enterprise

Introduction Enterpr ise Odoo has a variety of view kinds, including list, form, tree, kanban, graph, pivot, calendar, cohort, and more. Cohort views are a kind of reporting view in Odoo that let us monitor and evaluate user behavior across time. Rows and columns are displayed in the cohort view. We may simply obtain data on a day-by-day, weekly, monthly, and annual basis by looking for the intersection of a row and column, which displays a specific metric or value for that cohort in that particular period.

Enterprise To create a cohort view in Odoo, we need to define a model with the required fields

Enterprise create a new model and add a menu action under the configuration tab. Below is python code for creating a new class in Odoo. 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") email = fields.Char(related="employee_id.work_email") date = fields.Date(string="Date", required=True)

Enterprise We can choose employees from hr.employee in the newly created class EmployeeDetails. Since the phone and email fields are configured as linked fields, they will immediately fill in when we choose employees. Added a date field and made it mandatory since the date in cohort view was set to date_stop.

Enterprise Then, we need to give security for the above model. For that, create a new directory with a new csv file. Specify an id, name, and model id here. And give this security file in the manifest file. id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access.emp_details,access_emp_details,model_employee_details,base.group_user,1,1,1,1

Enterprise Before creating a cohort view add “web_cohort” as a dependent module in the manifest file. Next, we can create an xml file to create a view. First, we want to create ir.actions.act.window model with model name employee.details, and here we need to specify the view mode which type required, below mentioned the view as tree, form, and cohort. And set an id employee_details_action_menu to provide menu action for our model and give this id as action in the menu item.

Enterprise <record id="employee_details_action_menu" model="ir.actions.act_window"> <field name="name">Employee Details</field> <field name="res_model">employee.details</field> <field name="type">ir.actions.act_window</field> <field name="view_mode">tree,form,cohort</field> </record>

Enterprise For creating a cohort view, first need to give an id for the record and specify the model as ir.ui.view. And give a field name and add the model as employee.details. After that, mention the desired string for cohort tag, set date_start as create date, then take the date_stop from the newly created module, and we can provide the interval as day, week, month and year, and here the mode is set as churn.

Enterprise <record id="employee_details_view_cohort" model="ir.ui.view"> <field name="name">employee.details.view.cohort</field> <field name="model">employee.details</field> <field name="arch" type="xml"> <cohort string="Analysis" date_start="create_date" date_stop="date" interval="day" mode="churn"/> </field> </record>

Enterprise Then set the menu action for the model. In the menu item tag, set action as the record id which is mentioned above, and set the parent where we want to show the menu item. <menuitem id="employee_details_menu_root" name="Employee Details" action="employee_details_action_menu" parent="hr.menu_config_employee" sequence="20"/>

Enterprise We can see the Employee Details menu just click on that can see the details

Enterprise Click on the menu, it will open a new model in the tree view format, where we can create new records.

Enterprise Click on the cohort view icon and we can see the report of the records day wise in the UI.

For More Info. Check our company website for related blogs and Odoo book. Check our YouTube channel for functional and technical videos in Odoo. Enterprise www.cybrosys.com