Help

2

Sum on QWeb reports

Avatar
José

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.

1 Comment
Avatar
Discard
Avatar
Vasanth
-

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

2 Answers
6
Avatar
Zbik
Best Answer

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>

17 Comments
Avatar
Discard
Avatar
José
-

I get RESULT=100

Avatar
Zbik
-

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

Avatar
José
-

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.
Avatar
Zbik
-

Your code? PS. test_variable must be defined before loop

Avatar
Zbik
-

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

Avatar
José
-

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

Avatar
Zbik
-

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

Avatar
Zbik
-

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

Avatar
José
-

I don't understand, where is my mistake?

Avatar
José
-

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

Avatar
Zbik
-

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

Avatar
José
-

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

Avatar
Zbik
-

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/

Avatar
José
-

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

Avatar
Zbik
-

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

Avatar
José
-

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!

Avatar
Zbik
-

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

2
Avatar
kirubanidhi
Best Answer

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>

Avatar
Discard