How to Create Cohort View in Odoo 17 Enterprise
Introduction Enterprise 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

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

  • 1.
    How to CreateCohort View in Odoo 17 Enterprise
  • 2.
    Introduction Enterprise Odoo has avariety 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.
  • 3.
    Enterprise To create acohort view in Odoo, we need to define a model with the required fields
  • 4.
    Enterprise ● create anew 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)
  • 5.
    Enterprise ● We canchoose 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.
  • 6.
    Enterprise ● Then, weneed 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
  • 7.
    Enterprise ● Before creatinga 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.
  • 8.
    Enterprise <record id="employee_details_action_menu" model="ir.actions.act_window"> <fieldname="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>
  • 9.
    Enterprise ● For creatinga 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.
  • 10.
    Enterprise <record id="employee_details_view_cohort" model="ir.ui.view"> <fieldname="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>
  • 11.
    Enterprise ● Then setthe 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"/>
  • 12.
    Enterprise We can seethe Employee Details menu just click on that can see the details
  • 13.
    Enterprise Click on themenu, it will open a new model in the tree view format, where we can create new records.
  • 14.
    Enterprise Click on thecohort view icon and we can see the report of the records day wise in the UI.
  • 15.
    For More Info. Checkour company website for related blogs and Odoo book. Check our YouTube channel for functional and technical videos in Odoo. Enterprise www.cybrosys.com