Odoo Help


Porcentages in graph view

Lester Oscar
on 3/11/16, 9:26 AM 1,877 views

There is a way in odoo v8 to show the percentages in the graph view, for example, if I filter a model by sex, that I can see 80% women and 20% men, and if I apply another filter such as age> 43, keep the result in porcent, currently only graphics me the sum of the values filtered.


Axel Mendoza

--Axel Mendoza--
| 7 8 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full-time employee trying to understand what to do and how

Reach me at aekroft@gmail.com

Axel Mendoza
On 3/17/16, 4:07 AM

The thing is that the results to render graph view is tied to the use of read_group method using the group_operator argument of the field definition that by default is sum when you don't define the group_operator. That field argument only works with aggregated functions in postgresql and percent is not an aggregated function for postgresql.

You could do it by overriding the read_group method of the graph view model to manually change the field value for the result. Like:

def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False, lazy=True):

read_group_res = super(your_model self).read_group(cr, uid, domain, fields, groupby, offset=offset, limit=limit, context=context, orderby=orderby, lazy=lazy)

for res in read_group_res:

domain_filter = res.get('__domain', [])

line_ids = self.search(cr, uid, domain_filter, context=context)

if line_ids:

res_id = self.browse(cr, uid, line_ids[0], context=context)

res['results'] = res_id.results

return read_group_re

As the docstring of the read_group methods states:

:return: list of dictionaries(one dictionary for each record) containing:

* the values of fields grouped by the fields in ``groupby`` argument

* __domain: list of tuples specifying the search criteria

* __context: dictionary with argument like ``groupby``

Use this example to build your own solution based on your needs

Why don't you write about the 'graph view model'? I don't find a model who has 'graph' in the name...

Pascal Tremblay
on 2/26/17, 4:24 PM

it's not a model, it's a js view classes that implements the graph views behaviors

Axel Mendoza
on 2/26/17, 6:49 PM

My override of read_group method works now in the stock.quant model. I can see log of the variable and the returned dictionnary.

To display percentage instead/with the qty, do I have to create a new field in the model?

Should we instead modify the 'qty' in the dictionnary?

Do you know other urls that could show a complete example of displaying percentage on pie graph?


Pascal Tremblay
on 2/27/17, 10:16 AM

You could see this complete example https://github.com/odoo/odoo/blob/9.0/addons/product_margin/product_margin.py#L12-L115

You could modify the qty value but better create another field because it's a field that it's used for a lot of calculations and perhaps you could be altering results in some ways as read_group is not just used for graph views, just create another field

Axel Mendoza
on 2/27/17, 10:58 AM
Lester Oscar
On 3/11/16, 11:27 AM

Ibra thanks very much for your answer but the problem is that i need see the porcentage related whit all my models in a graph view, for example if i have 5 employees, 3 male and 2 female when i filter for sex in my graph view for hr_employee model i wan to see the result of all my models in porcent, not the quantity like by default odoo work. 

On 3/11/16, 10:25 AM

Hello Oscar,

you can use a widget called progressbar for this :

<field name="your_field" widget="progressbar"/>

to show the percentages, your field should be computed.
example :  add the percentage of taken seats

you .py :

seat = fields.Integer(string="Number of seats")

attendees_ids = fields.Many2many('res.partner', string="Attendees")

taken_seats = fields.Float(string="Taken seats", compute='_taken_seats')

then you add the decorator depends because taken seats depends on both seats and attendees

@api.depends('seat', 'attendees_ids')

def _taken_seats(self):

    for r in self:

        if not r.seat:

            r.taken_seats = 0.0


        r.taken_seats = 100.0*len(r.attendees_ids)/r.seat

your .xml :

<field name= "taken_seats" widget="progressbar"/>

this is a simple example on how to dislay percentage. Try to work on your own example with the same logic and tell us if it works.

Best regards. 

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/11/16, 9:26 AM
Seen: 1877 times
Last updated: 3/17/16, 4:07 AM