Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

how to pass qweb variable values within html elements in a loop?

By
Abdullah Sofan
on 12/28/14, 9:21 AM 2,372 views

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?
 

0

Jérémy Kersten (jke)

--Jérémy Kersten (jke)--
2993
| 3 2 5
Jodoigne, Belgium
--Jérémy Kersten (jke)--

Jérémy is a member of the core R&D team since september 2013. He developed several projects for OpenERP version 8 including the eCommerce, the Google Calendar synchronization and the new product variants/configurator. Now, he manages Odoo website and themes for saas.

Jérémy Kersten (jke)
On 1/30/15, 9:04 AM

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

 

0
Abdullah Sofan
On 12/28/14, 9:32 AM

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

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/28/14, 9:21 AM
Seen: 2372 times
Last updated: 3/16/15, 8:10 AM