I did a bit of research, digged in and learned some Latex and made a proof-of-concept.
What I did was creating a table with the
longtable package. Using this package you will be able to add a main header and footer and a page header and footer. The first ones are only added at the start and the end of the table, the seconds ones are added on each page if the table spans more then one page.
Using the output macro of the table, you will get the ‘running row’. If that row is a header or footer you can then move in your subtotals. The counting is done in a special counter which is triggered by each row. It will never be set to zero, so you have a ‘running total’.
In this case the main header and footer is not used or needed because this is only about the subtotals.
ONLY the amount is counted to display the subtotals. All the other data and totals should come from Tryton. Below a screenshot how this looks like.
tex-template is a bit of a mess at the moment. If anybody is interested, please let me know so I can clean it up, comment it and make it work with Tryton as a report. Basically ALL the data is coming from Tryton, only the subtotals are in the template counted so no business logic is needed for this. Maybe there can be a rounding error but not tested yet.