Create sort_ function for functional field


I was reading the docs about functions to order funtional fields [6], [7] and reviewing some examples on tryton git [0], [1], [2], [3], [4], [5] but I could not find and example on how to use for a specific case that have.

Basically I have a model to record the gathering moves of every month and a group. Every group have more than 5 people, it will vary:


Group, Month, Date,

Moves Lines:

Move, Party, Amount

I added a custom field that calculate on Party that get the sum of the move lines and it works fine, but I wish to order from highest to lowest.

Where could I find an example of how can order these type of field?

Thanks in advance!

[6] Fields — trytond 5.3 documentation
[7] Fields — trytond 5.3 documentation

There is no such example because it would be resource consuming.

Any way, you have to make a join (adding to tables argument) with a query the will return the party id and the SUM. Then you return the clause to order with the SUM column of your query.

1 Like

I just updated the training module with an example of an “order” method implementation:

Search for “Defining a order method”

Edit : For your use case, you would have to add an entry in the “tables” dict which is a full sub-query.

1 Like