Merge lp:~numerigraphe/openobject-server/trunk-read_group-having into lp:openobject-server
Status: | Rejected |
---|---|
Rejected by: | Fabien (Open ERP) |
Proposed branch: | lp:~numerigraphe/openobject-server/trunk-read_group-having |
Merge into: | lp:openobject-server |
Diff against target: |
41 lines (+14/-3) 1 file modified
openerp/osv/orm.py (+14/-3) |
To merge this branch: | bzr merge lp:~numerigraphe/openobject-server/trunk-read_group-having |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
OpenERP Framework Experts | Pending | ||
OpenERP Core Team | Pending | ||
Review via email: mp+104579@code.launchpad.net |
Description of the change
This branch adds a new parameter named "having" to orm.read_group(), that lets clients pass the information to filter the grouped records based on the sum (or avg, etc.) of a value.
This parameter should contain a domain-like list of tuples, that the ORM will use to add a "HAVING" clause to the SQL query.
For an example of how this feature is useful, please see lp:~numerigraphe/openobject-addons/trunk-stock-analysis-filter-zero, where we use the "having" parameter to filter out results with quantity = 0 in stock analysis. This can only be done after the records have been grouped (the goods may have gone in then out of a location).
This is only really useful if clients support it too. Support for the GTK client has been added in lp:~numerigraphe/openobject-client/trunk-read_group-having.
Lionel Sausin & Philippe Rossi.
Hi Philippe and Lionel,
The need to allow filtering on the _result_ of read_group queries rather than the source rows is dire and has been discussed in the past, so it is great to see you work on it!
Please have a look at comment #11 of bug 743715, I think it describes the context in more details.
Based on what I wrote in that comment, I think we may perhaps find an elegant approach to solving this issue that does not require to modify the OpenERP clients or introduce more context parameters, etc. The idea would be to completely switch the behavior of read_group from using a WHERE clause to a HAVING clause as soon as we are in "analysis" mode, i.e. when `group_by_no_leaf` is passed in the context. It seems a reasonably logical behavior with no much side effects, and it looks like it would certainly work for your stock analysis use case.
What do you guys think? Does it seem to make sense to you too? If yes, would you be willing to validate this approach with a rework of your patch in that direction?
Thanks!