Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
43731 Tampilan

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.

Avatar
Buang

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

Jawaban Terbai

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>

Avatar
Buang
Penulis

I get RESULT=100

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

Penulis

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.

Your code? PS. test_variable must be defined before loop

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

Penulis

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

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

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

Penulis

I don't understand, where is my mistake?

Penulis

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

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

Penulis

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

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/

Penulis

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

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

Penulis

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!

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

Jawaban Terbai

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
Buang
Jawaban Terbai

Qweb code to sum the amount by column:

<td>

<t t-set="sum_row2" t-value="0"/>
<t t-foreach="doc.line_ids" t-as="line">
<t t-set="sum_row2" t-value="sum_row2+line.amount_2"/>
</t>
<t t-esc="sum_row2"/>
</td>


For example (sum Amount_2 column):

Amount_1Amount_2
010
020

30
Avatar
Buang

thanks

Post Terkait Replies Tampilan Aktivitas
2
Mei 15
7704
0
Mar 15
2770
1
Mar 15
11684
2
Sep 24
1833
1
Jun 21
7934