Development Book V17: Cohort view

The cohort view is one of the Odoo views that provides information for the next 15 days, weeks, months, and years. Let's look at an example to see how we can get a good data analysis in a specific time frame.

from odoo import models, fields
                            class ModelExample(models.Model):
                                _name = 'model.example'
                                patient_id = fields.Many2one('hospital.patient', string="C")
                                name = fields.Char(string='Name')
                                date = fields.Date(string="Date")
                                attachment = fields.Binary(string="Attachment")
                            class HospitalPatients(models.Model):
                                _name = 'hospital.patient'
                                name = fields.Char(string='name')
                                dob = fields.Date(string='date')

After we've added models, we can customise their actions and menus.

                            <record id="action_Example1" model="ir.actions.act_window">
                               <field name="name">Example1</field>
                               <field name="type">ir.actions.act_window</field>
                               <field name="res_model">model.example</field>
                               <field name="view_mode">tree,form,cohort</field>
                            <menuitem id="model_example_menu"
                                      name="Model Example"

We can now configure the model's cohort view.

                                <record id="model_example_cohort" model="ir.ui.view">
                                <field name="name">model.example</field>
                                <field name="model">model.example</field>
                                <field name="arch" type="xml">
                                    <cohort string="model" date_start="date" date_stop="date" interval="day" sample="1"/>

Don't forget to include 'web_cohort' in the depends; otherwise, an error will occur.

In cohort view, there are two types of modes: retention and churn. Churn begins at zero and ends at zero. Retention will begin at 100% and gradually decrease to zero.

The above code will produce the following result:



Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635



Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.



Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message