Enable Dark Mode!
how-to-create-cohort-view-odoo-13.png
By: Thomas Job

How to Create Cohort View in Odoo 13

Technical Odoo 13

Sometimes we may need a better understanding of data changes over a specific time frame. In Odoo we can make use of cohort view for this kind. Cohort view will give the report of data changes that took place over a time frame. Below shown the image is the cohort view of Warehouse Analysis. Note: Cohort view is only available in Odoo enterprise edition.

how-to-create-cohort-view-odoo-13-cybrosys

Now let's look at how to create a cohort view in Odoo. Let’s create a new module to test how to create a cohort view.

Here I am creating a module cohort_test. While configuring the manifest.py file gives dependency to ‘web_cohort’, web_cohort has the framework to create the cohort view.

Add this in manifest.py file:
          
'depends':  ['web_cohort'],

Create the model. I have created a model ‘cohort.cohort’ for testing. And add the fields. Cohort views need at least one date field in order to work.

class CohortTest(models.Model):
    _name = 'cohort.cohort'
    name = fields.Char(string='Name', required=True)
    date_end = fields.Datetime(string='Date end')

Now create the view in XML,

<record id="view_cohort_cohort" model="ir.ui.view">
      <field name="name">cohort.cohort.test</field>
      <field name="model">cohort.cohort</field>
      <field name="arch" type="xml">
        <cohort string="Cohort records" date_start="create_date" date_stop="date_end" interval="day" mode="churn"/>
      </field>
    </record>
                
Add the ‘cohort’ attribute in view so Odoo can create the cohort view. There are two modes: "churn" and "retention". Churn mode will start at 0% and increase over time whereas retention will start at 100% and decrease over time. Here mode="churn" is used. Start date of the record is taken from date_start and end date of the record is taken from date_stop, interval parameter will give the interval, here it is ‘day’

Add a security rule in 'ir.model.access.csv' to access the view.

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,per_unlink
Access_cohort_cohort,cohort.cohort,model_cohort_cohort,base.group_user,1,1,1,1

Now create the menu item.

<menuitem id="cohort_menu_root" name="Cohort Test"/>
 
This will show as an App.

Now create action and submenu.

<record id="action_cohort" model="ir.actions.act_window">
      <field name="name">Records</field>
      <field name="type">ir.actions.act_window</field>
      <field name="res_model">cohort.cohort</field>
      <field name="view_mode">tree,form,cohort</field>
</record>

This XML code will give the action to view the cohort view. Create a menu item for the working of action ie the submenu,

<menuitem id="cohort_menu" name="Records" action="action_cohort" parent="cohort_menu_root" sequence="1"/>

This menu item will open the cohort view.
 
Now install the module. We will get the cohort view like the below image.

how-to-create-cohort-view-odoo-13-cybrosys

Thus we can create a cohort view.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

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

location

Kochi

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

location

Bangalore

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

Send Us A Message