콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
44126 화면

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
8007
0
3월 15
2994
1
3월 15
11992
2
9월 24
2244
1
6월 21
8184