Compute values in grid-view

I am new to Axelor and I am trying to compute the sum of a list in the grid-view but not able to figure out the flow of the actions and views.
I prefer to compute the sum of a ManyToOne field on load of grid for each record and display in grid in a new field, but in case that is not possible, I am open to compute the same on click of a button from the view.
Is there any existing implementation that I can refer to for further information? If not, can someone please guide me through this?

Hello @godfather,

Welcome to Axelor and sorry for the late response.
You have a lot of imagination and your solutions deserve to be tested.
I propose a solution which works, but which is not necessarily the best.
Maybe other members will provide other solutions.

Create a new total_amount field in the grid.

Create an action-record action-record-total which calculates the total.

<action-record name="action-record-total"  model="...">
<field name="total_amount" expr="eval: field_amount_1 + field_amount_2" />

</action-record>

In the grid, put an action trigger onChange, to refresh the total amount, each time you change the value of an existing field (here the example of field_amount_1 and field_amount_2)

…/…
<field name=« field_amount_1 » … onChange=« action-record-total » />
<field name=« field_amount_2 » … onChange=« action-record-total » />
…/…

Some useful links:

https://docs.axelor.com/adk/5.4/tutorial/index.html

https://docs.axelor.com/adk/5.4/dev-guide/actions/index.html

https://docs.axelor.com/adk/5.4/dev-guide/actions/action-record.html

Hope this can help you.