Odoo Help

2

Sum on QWeb reports

By
José
on 3/30/15, 7:07 PM 7,993 views

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

Vasanth
on 3/31/15, 3:46 AM
4
Zbik
On 3/31/15, 3:53 AM

Try like this:


<t t-set="test_variable" t-value="100"/>
<p t-foreach="[10, 20, 30]" t-as="i">
  <t t-set="test_variable" t-value="test_variable+i"/>
</p>
<h1>RESULT=<t t-esc="test_variable"/></h1>

I get RESULT=100

José
on 3/31/15, 9:10 AM

You update your code, see this commit: https://github.com/odoo/odoo/commit/4a698da8b37055922be75a85f76d750dfbbadd42

Zbik
on 3/31/15, 9:12 AM

I do: Loop... (Where "l" is the item on which loop) End of loop...

Total: $

and I get total: 0 at the end. Why? l.amount_total is not 0, I display these values and there are not 0.
José
on 3/31/15, 9:19 AM

Your code? PS. test_variable must be defined before loop

Zbik
on 3/31/15, 9:28 AM

Variable "l" after loop no more exists in global context!

Zbik
on 3/31/15, 9:35 AM

See the code in my question, I edit it. Here is the complete code.

José
on 3/31/15, 9:40 AM

You loops many object .... foreach="docs" ... probably variable scope is only one object, I test later.

Zbik
on 3/31/15, 10:02 AM

In my test system, total with ... foreach="docs" ... works ok!

Zbik
on 3/31/15, 10:18 AM

I don't understand, where is my mistake?

José
on 3/31/15, 12:05 PM

I try your code, I copy it exactly, and I get "RESULT=100"... so what is the problem?

José
on 3/31/15, 12:17 PM

Your system is updated and include commit to which I gave the link?

Zbik
on 3/31/15, 12:32 PM

Probably my system is not updated. What is the best way to update Odoo without losing information?

José
on 3/31/15, 12:38 PM

Update procedure depends on what you are running linux or windows, and how it is being installed See https://doc.odoo.com/install/linux/updating/

Zbik
on 3/31/15, 12:50 PM

I have Windows 7 x64. If I download the branch, https://github.com/odoo/odoo it is for Windows?

José
on 3/31/15, 1:23 PM

My suggestion, you use http://nightly.odoo.com/ and read https://www.odoo.com/documentation/8.0/setup/install.html

Zbik
on 3/31/15, 2:33 PM

It works! Please check if I updated Odoo correctly. 1) Download nightly latest version .exe. 2) Copy "addons" folder to temp directory. 3) Delete old version of Odoo. 4) Install new version of Odoo. 5) Copy "addons" folder to the addons folder of the new version of Odoo. At the moment, all works OK, I do the update correctly? Thanks you a lot!

José
on 3/31/15, 5:25 PM

next step... update all modules ... or select as admin, module "base" (from module list) and update it.

Zbik
on 3/31/15, 5:29 PM
0
kirubanidhi
On 7/7/16, 8:58 AM

Calculate total fine amount code. Book_id is a one2many fields.

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

<t t-foreach="doc.book_id" t-as="l">

                    <t t-set="test_variable" t-value="test_variable+l.fine" />

                    <td class="text-right">

                            <span t-field="l.fine" />

                    </td>

</t>

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/15, 7:07 PM
Seen: 7993 times
Last updated: 7/7/16, 8:58 AM