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).