Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
10272 Vistas

I have this code from a qweb html report. Please look at the bold segments.


<table class="table-condensed" style="font-size: 10px; width:100%">
                        <thead>
                            <tr>
                                <th style="border: 1px solid black;background-color:black;color:white;">
                                    Student Name
                                </th>
                                <th t-foreach="o.batch_att_sheets" t-as="sheet" style="text-align: center; border: 1px solid black;background-color:black;color:white;">
                                    <span t-field="sheet.attend_date" t-field-options="{&quot;format&quot;: &quot;d&quot;}"/>
                                    <br/>
                                    <span t-field="sheet.attend_date" t-field-options="{&quot;format&quot;: &quot;MMM&quot;}"/>
                                    <br/>
                                </th>
                                <th style="border: 1px solid black;background-color:black;color:white;">
                                    Attendance Percentage
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr t-foreach="o.batch_registrations" t-as="line" style="border: 1px solid black;">
                                <td>
                                    <span t-field="line.student_name"/>
                                    <t t-set="att_counter" t-value="0"/>
                                </td>
                                <td t-foreach="o.batch_att_sheets" t-as="sheet" style="text-align: center;border: 1px solid black;">
                                    <t t-set="attended" t-value="o.get_attendance(o.name,line.student_name.id,sheet.name)"/>
                                    <t t-if="attended == 'Y'">
                                        <p>Y</p>
                                        <t t-set="att_counter" t-value="att_counter+1"/>
                                        
                                     </t>
                                    <t t-if="attended == 'N'">
                                        <p style="color: red;">
                                            <strong>N</strong>
                                        </p>
                                    </t>
                                </td>
                                <td>
                                    <t t-esc="att_counter"/>
                                </td>
                            </tr>
                           
                        </tbody>
                    </table>

 

The code is supposed to add 1 to the value of att_counter. However, on the last t-esc I still get a 0. Somehow the value is not persistant after the loop. 

Can someone help me?
 

Avatar
Descartar
Mejor respuesta

Hello,

A discussion exits on github, you can check here https://github.com/odoo/odoo/issues/4461#issuecomment-72199618 the explication of Odony to know how to do it easily...

The propagation has been added since commit 4a698da (https://github.com/odoo/odoo/commit/4a698da) but in most case it should not be used to make sum, ... Qweb is for templating... 

 

Have a good day

 

JKE

 

Duplicated:

https://www.odoo.com/forum/help-1/question/how-to-pass-qweb-variable-values-within-html-elements-in-a-loop-71675

https://www.odoo.com/forum/help-1/question/qweb-loop-cannot-set-value-to-vaiables-outside-the-loop-71486

https://www.odoo.com/forum/help-1/question/qweb-get-variable-value-from-loop-74531

https://github.com/odoo/odoo/issues/4461

 

Avatar
Descartar
Autor Mejor respuesta

I found this question with the same issue. Is this a common bug?
https://www.odoo.com/forum/help-1/question/qweb-loop-cannot-set-value-to-vaiables-outside-the-loop-71486

 

Avatar
Descartar