Skip to Content
Menú
This question has been flagged
1 Respondre
12917 Vistes

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.

Avatar
Descartar
Best Answer

Hello James,


Try below code :-

<t t-set="total" t-value="0"/>

<table class="table_border" style="font-size:10px;">                             <!-- First Table -->

    <thead>

        <tr>    

            <th>Cantidad</th>

       </tr>

   </thead>

   <tbody>

        <td>

            <span t-field="o.cantidad_field"/>

            <t t-set="total" t-value="total+o.cantidad_field"/>

        </td>

    </tbody>

</table>

<p>Resumen</p>

<table class="table_border" style="font-size:10px;">                             <!-- Second Table (Total) -->

    <thead>

        <tr>    

            <th>Total Cantidad</th>

       </tr>

   </thead>

    <tbody>

        <td>

            <span t-esc="total"/>

        </td>

    </tbody>

</table>


This is for Cantidad Field and from this You can also get total of Precio Unitaro and Precio.


Hope this will helps you.

Thanks,

Avatar
Descartar
Autor

Thank you very much, but now odoo shows me the following error: QWebException: need more than 1 value to unpack