Function field in table_query

Hello again Tryton community !
This topic is linked to this one where I discussed on how to display a “group by” table in a tree view. I am trying to implement this solution suggested by ced, but I am experiencing some difficulty (I am new to Tryton).
I would like to implement a model based on a table_query, which would return the table of purchases group by party and the sum on the total_amount column.

I noticed that I could not select the total_amount field, because, as a function field, its value is not stored in the database, so there is no total_amount column in the Purchase table.

My question is : what could I implement to manage to display the value of this field in my table_query ? I tried to create a new field with an on_change_total_amount method to store the value of total_amount in a field stored in the database. But apparently I cannot base an on_change method on a function field too…

So what could be a solution to display a function field in the list of a model based on a table_query ?
Thank you for your help, and sorry for the vocabulary mistakes if there are any.

As the value of this field is not stored in the database, you will need to add a function field to your model to calculate its value. Perhaps you can take some inspiration from: modules/sale: 8848150a4586 sale_reporting.py

If you only care about purchases that are confirmed, done, or cancelled, then you may be able to use the value in the total_amount_cache column from the database.