How to Add Statistic Buttons on Odoo Form?

Let's assume that we are working on a SCRUM environment and have a One2many field on the Project object to Release object.

class project(models.Model):
    _name = 'project.project'
_inherit = 'project.project'

    epic_ids = fields.One2many(comodel_name="vit_scrum.epic", inverse_name="project_id", string="Epics", required=False, )
release_ids = fields.One2many(comodel_name="vit_scrum.release", inverse_name="project_id", string="Releases", required=False, )

Now we need to display the number of Releases on a particular Project. We need to add a new button on the Project form, showing the total number of Releases for that Project. For example:

When the Release button is clicked, then the Releases corresponding to that Project is displayed.

Also, when we click Create button on the Release list, then the project field is automatically filled with the current Project.

Here's how to do that:

First we need a functional field to calculate the total number of Releases the Project has:

class project(models.Model):
    _name = 'project.project'
 _inherit = 'project.project'
    epic_ids = fields.One2many(comodel_name="vit_scrum.epic", inverse_name="project_id", string="Epics", required=False, )
 release_ids = fields.One2many(comodel_name="vit_scrum.release", inverse_name="project_id", string="Releases", required=False, )

    def _compute_release_count(self):
        for project in self:
            project.release_count = len(project.release_ids)

release_count = fields.Integer(string="Release Count", required=False, compute='_compute_release_count')

Then, we modify the Project form, by adding our new button and displaying the number of Release inside:

<record id="project_scrum" model="ir.ui.view">
 <field name="name">project_scrum</field>
 <field name="model">project.project</field>
 <field name="inherit_id" ref="project.edit_project"/>
 <field name="arch" type="xml">
        <div name="button_box" position="inside">
  <button class="oe_stat_button"
context="{'search_default_project_id': active_id, 'default_project_id': active_id}"
 <field string="Releases" name="release_count" widget="statinfo" />

What we did here:

  1. Inherit the project form by inserting the new statistic button inside the <div name="button_box">

  2. The button type of "action"

  3. The button name is the name of the  action window we need to open, in this case the decimal number of the action window that has the ID of act_open_vit_scrum_release_view

  4. The most important part is the context which is the default context to be used as the default filter at the time the action is opened, which is search_default_project_id = active_id and the default_project_id = active_id to set the default value of the form containing the project_id field

  5. The active_id is the currently opened Project Id.

This topic is part of the "Advanced Odoo Programming Techniques" provided by For more information please visit


Videos fill be uploaded regularly, so subscribe our youtube Channel.

Visit YouTube Channel

Untuk trik Odoo lainnya bisa cek Udemy courses

Visit official site

One Touch and Go Live with Odoo


Check our blog:

accounting,belajar erp,belajar odoo,business software,cloud computing,crm,dunia erp,enterprise resource planning,erp,erp software,erp system,event,inventory,it,it erp,mrp,odoo,odoo 11,odoo consultant indonesia,odoo erp,odoo indonesia,odoo tutorial bahasa indonesia,odoo tutorial indonesia,openerp,point of sales,pos,purchase,software as a service,tinyerp,tutorial odoo,tutorial odoo indonesia,odoo indonesia week,odoo indonesia payroll,odoo 13 indonesia

How to Add Statistic Buttons on Odoo Form?
vitraining, odoo indonesia
16 May, 2020
Share this post
Sign in to leave a comment
Hide field in a tree view