跳至内容
菜单
此问题已终结
3 回复
43106 查看

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

最佳答案

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

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

编写者

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!

编写者

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!

编写者

I don't understand, where is my mistake?

编写者

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?

编写者

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/

编写者

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

编写者

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.

最佳答案

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>

形象
丢弃
最佳答案

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
形象
丢弃

thanks

相关帖文 回复 查看 活动
2
5月 15
7344
0
3月 15
2544
1
3月 15
11302
2
9月 24
1198
1
6月 21
7416