Odoo Help

0

How to sum fields in a view Qweb?

By
James Ford
on 3/30/16, 5:06 PM 1,406 views

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.

1

Jignesh Mehta

--Jignesh Mehta--
2206
| 6 5 8
Surat, India
--Jignesh Mehta--


Jignesh Mehta
On 3/31/16, 12:26 AM

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,

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

James Ford
on 3/31/16, 11:40 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 3/30/16, 5:06 PM
Seen: 1406 times
Last updated: 3/31/16, 12:26 AM