I am creating a report (qweb view) in the account.invoice model and wish to sum some fields for each invoice line as shown in the following image:
Image: http://es.zimagez.com/zimage/facturaborrador.php
The problem is that not sum the fields as I want. What should I do?
cantidad_producto = fields.Integer(string='Cantidad Producto', store=True, readonly=True, compute='cantidad_consolidado')
total_precio_unitario = fields.Monetary(string='Total precio unitario', store=True, readonly=True, compute='cantidad_consolidado')
total_precio_neto = fields.Monetary(string='Total Cantidad Producto', store=True, readonly=True, compute='cantidad_consolidado')
And this is my function compute in the file account.invoice.py:
@api.one
@api.depends('invoice_line_ids.quantity', 'invoice_line_ids.price_unit', 'invoice_line_ids.price_subtotal')
def cantidad_consolidado(self):
self.cantidad_producto = sum (line.quantity for line in self.invoice_line_ids)
self.total_precio_unitario = sum (line.price_unit for line in self.invoice_line_ids)
self.total_precio_neto = sum (line.price_subtotal for line in self.invoice_line_ids
And finally, this is my view code:
<p>Resumen</p>
<table class="table table-bordered">
<thead>
<tr>
<th class="text-center">Total Cantidad</th>
<th class="text-center">Total Precio Unitario</th>
<th class="text-center">Total Precio(Neto)</th>
</tr>
</thead>
<tbody class="invoice_tbody">
<td class="text-center">
<span t-esc="cantidad_producto" />
</td>
<td class="text-center">
<span t-esc="total_precio_unitario" />
</td>
<td class="text-center">
<span t-esc="total_precio_neto" />
</td>
</tbody>
</table>
Why do not sum the fields in the report? Someone could tell me and so help me Please. Thank you very much for your help.