Sunday, August 17, 2014

Group with aggregation, Sort and Filter on Function Field in OpenERP

For OpenERP Version 6, we could not sorting and filtering on function field. Also we could not have group by with aggregation (Sum) on Function fields in OpenERP.

So the work around here we need 1 more field, this is not function field, but its a real field. We add this real field to Tree view, and invisible the function field.
When we calculating the function field, we update the real field = function field value, so that we can have the Tree view sorted by a function field.

I have an example here:


Let say we have the function field: last_check_out_calc which is calculated by function "get_last_check_out", beside this field we add one more real field: "last_check_out", so in the funtion "get_last_check_out" we calculate for field "last_check_out_calc" and we update "last_check_out_calc" value for "last_check_out".

Save the value into OpenERP Database by using write ORM function!
self.pool.get('project.task').write(cr, uid, [item_id], {'last_check_out': item_checkout_time})

Then we can order by "last_check_out".
We have to "last_check_out_calc" on the Tree view, but should keep it be invisible.

No comments:

Post a Comment