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

Graph view : use fields.function

By
Assem
on 6/3/14, 6:27 AM 1,688 views

Hello,

I'm trying to create a graph bar view : My problem is that when I use a fields.function to calculate datas, the values are not right and it seems that the fields.function is not called! But when I use a simple fields.integer, it works fine.

To be sure that my fields.function is correctly defined and the calculation is good, I added it to the form view and it works fine.

Lastly, if I add store=True to the fields.function, it works, but I don't want to store the calculated data in the DataBase.

Thanks for your help.

 

 

 

 

1

Well, you had the right idea by storing the value.  Unfortunately, right now, it is the only solution.

 

The way the graph view gets its data is by calling the read_group method in the ORM.  That method will collect the data from the database.  This means that the aggregation (sum) is done by postgres (and is very fast) instead of being done by the python code (not so fast).

 

So, right now, the design of the graph view makes it impossible to aggregate functional fields if they are not stored.  A possible solution is to add a controller to the graph view.  That controller could call read_group itself, then, perform additional requests to the database to aggregate manually on all non stored functional fields.  It would probably be much slower, but the additional functionality might be worth it.

 

 

@GED: can you explain how to create controller for graph view? If possible give one example. Thank you.

Jaysinh Shukla (jsh)
on 9/15/14, 3:15 AM

i could, but this would be quite involved. It is a non trivial task, and of course, I don't have so much time. Doing this would require adding a controller which will acts as a specialized read_group, calling read_group when possible, and aggregating the data when a functional field is not stored, then the graph view could in theory call that controller instead of readgroup. However, (1) that controller would be difficult to program, because the groupbys could be any combinaison of functional fields and normal fields, and you want to use the native read_group as much as possible, (2) I am not sure that this is a good idea performance wise. It will probably be too slow (and too cpu/memory hungry) when aggregating millions of rows.

Géry Debongnie (ged)
on 9/16/14, 7:56 AM

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

2 follower(s)

Stats

Asked: 6/3/14, 6:27 AM
Seen: 1688 times
Last updated: 3/16/15, 8:10 AM