Odoo Help

Welcome!

This community 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.

0

Porcentages in graph view

By
Lester Oscar
on 3/11/16, 9:26 AM 746 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.

0

Axel Mendoza

--Axel Mendoza--
10238
| 7 7 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 an 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



0
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. 

0
ibra
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

   else:

        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. 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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