Contributors mailing list archives

contributors@odoo-community.org

Browse archives

Avatar

Re: Sort function field, which is not stored in the db

by
Holger Brunn
- 11/01/2018 10:44:09
> I have a function field, which I don`t want to store in the db.

> 

> The problem is that I want to be able to sort by this field in a tree

> view via click on the column header.

> 

> Is there a way to do this?

with jumping through a lot of hoops, there is. Reassess if you really
don't want to store the field, that's a world simpler and if it's not a
crazy amount of data, postgres doesn't care so much about an extra
column. Also think if you need to store all of the data for sorting, if
you can generate a numeric sort key, you could just save that, much faster.

If you really think you can't store this, you're up for some pain:
- override https://github.com/OCA/OCB/blob/11.0/odoo/models.py#L2401
such that https://github.com/OCA/OCB/blob/11.0/odoo/fields.py#L739 comes
back True for your field
- override https://github.com/OCA/OCB/blob/11.0/odoo/models.py#L3653
where you do the sorting manually. You'll have to analyze the sort
parameter, remove your field before passing it to super, and then do the
right thing for sorting afterwards. Don't expect performance miracles,
and I think supporting all features of sorting will actually be cumbersome.



-- 
Therp - Maatwerk in open ontwikkeling

Holger Brunn - Ontwerp en implementatie

mail: holger@therp.nl
web: http://therp.nl
phone: +31 (0)20 3093096

Reference