Hello, I have Odoo 8 and I am developing a QWeb report. Is there any way to sum any field in a t-foreach loop and then display the result of the sum? How?
Thanks!
EDIT
...
<t t-set="total" t-value="0" />
<table class="table table-condensed">
<thead>
<tr>
<th>Fecha</th>
<th>Documento</th>
<th>Detalle</th>
<th>Total sin impuestos</th>
<th>Total con impuestos</th>
</tr>
</thead>
<tbody class="sale_tbody">
<tr t-foreach="docs" t-as="l">
<td>
<span t-field="l.date_order"/>
</td>
<td>
<span t-field="l.name"/>
</td>
<td>
<table class="table table-condensed">
<thead>
<tr>
<th>Producto</th>
<th>Cantidad</th>
<th>Precio unitario</th>
<th>Fecha del viaje</th>
<th>Destino</th>
<th>Remito SyE</th>
<th>Chofer</th>
<th>Subtotal</th>
</tr>
</thead>
<tbody>
<tr t-foreach="l.order_line" t-as="a">
<td>
<span t-field="a.product_id" />
</td>
<td>
<span t-field="a.product_uom_qty" />
</td>
<td>
<span t-field="a.price_unit" />
</td>
<td>
<span t-field="a.fecha" />
</td>
<td>
<span t-field="a.destino" />
</td>
<td>
<span t-field="a.numero_remito" />
</td>
<td>
<span t-field="a.chofer" />
</td>
<td>
<span t-field="a.price_subtotal" />
</td>
</tr>
</tbody>
</table>
</td>
<tr>
<td /><td /><td />
<td>
<span t-field="l.amount_untaxed" />
</td>
<td>
<span t-field="l.amount_total" />
</td>
<t t-set="total" t-value="total+l.amount_total" />
</tr>
</tr>
</tbody>
</table>
<h3>Total: $<t t-esc="total" /></h3>
In bold I mark the lines where I do the sum.
Hi jose: In py file: def funct_total(self, form): result = [] res = {} res = { 'tot_num1': tot['num1'], 'tot_num1': tot['num2'], 'tot_total': tot['num1'] + tot['num2'], } result.append(res) return result In xml file( report file):