Correct use of variables in report templates (fodt)

sorry, but i really don’t get it :sweat_smile:

i’m trying to calculate the total amount of specific lines in the invoice report (“invoice.fdot”)

this is what i came up with so far:

<with vars="sum_loop=0">
  <for each="line in invoice.lines"> 
    <if test="line.account"> 
      <if test="line.account.code == '8402'">
  total of loop => <sum_loop> 

what is the correct line for xxxxx to have an expression like sum_loop=sum_loop+invoice.line

thank you

It is not advised to make computation in the template. You should make the computation on the instance or in the report context.
Genshi syntax does not have assignation statement. At best you could use Python sum if you set it in the context like sum(l.amount for l in invoice.lines if l.account.code == '8402')
Also you should probably avoid the hard-coding of code value and instead use a flag on the account (or type).

thank you for the quick reply - i will put this computation into the report context.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.