Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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.
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)
res_id = self.browse(cr, uid, line_ids, context=context)
res['results'] = res_id.results
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
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.
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
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.
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 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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 3/11/16, 9:26 AM|
|Seen: 826 times|
|Last updated: 3/17/16, 4:07 AM|