Odoo Help

0

odoo 8 qweb foreach array

By
Nischal
on 10/23/15, 6:05 PM 1,359 views

using the below code, i want to display unique packages and not duplicate them. But still i have one package gets duplicated if result_package_id is same for first and last iteration of pack_operation_ids. Is there a way to save all the result_package_id in a array and then match it in every loop of pack_operation_ids

            <?xml version="1.0"?>

            <t t-name="stock.report_picking_packaging">

            <t t-call="report.html_container">

            <t t-foreach="docs" t-as="o"> 

            <t t-set="prev" t-value="0" />

            <p> <t t-esc="prev"/><b>Prev: </b></p>

              <tr t-foreach="o.pack_operation_ids" t-as="n">

              <t t-set="new" t-value="n.result_package_id" />

                 <p><t t-esc="new"/><b>new: </b></p>

                 <p t-if="new != prev"><b>Package name: </b><span t-field="n.result_package_id"/></p>

                 <t t-set="prev" t-value="n.result_package_id" />

                <p> <t t-esc="prev"/><b>Prev: </b></p>

           <br/>

            </tr>

           </t>

          </t>

           </t>


below is the display

0Prev:

stock.quant.package(21,)new:

Package name: BOX0018

stock.quant.package(21,)Prev:

stock.quant.package(20,)new:

Package name: BOX0017

stock.quant.package(20,)Prev:

stock.quant.package(20,)new:

stock.quant.package(20,)Prev:

stock.quant.package(19,)new:

Package name: BOX0016

stock.quant.package(19,)Prev:

stock.quant.package(19,)new:

stock.quant.package(19,)Prev:

stock.quant.package(21,)new:

Package name: BOX0018

stock.quant.package(21,)Prev:




 Working code, help from Jaydeep Barot.

                   <t t-name="stock.report_picking_packaging">

                   <t t-foreach="docs" t-as="o">

                  <t t-call="report.html_container">

                 <h1>PACKAGES</h1>

                     <table class="table table-condensed" t-if="o.pack_operation_ids">

                     <thead>

                       <tr>

                       <th><strong>Package Name</strong></th>

                        </tr>

                       </thead>

                      <tbody>

                      <t t-set="package" t-value="list(set([ pack.result_package_id for pack in o.pack_operation_ids if                      pack.result_package_id]))"/>

                         <tr t-foreach="package" t-as="p">

                         <td><span t-esc="p.name"/>

                               <p><b>Package size (LXWXH): </b><span t-field="p.length"/><b>X</b><span t-field="p.width"/><b>X</b><span t-field="p.height"/></p>

                                 <p><b>Package net_weight: </b><span t-field="p.total_estim_weight_net"/><b>Package gross_weight: </b>                                    <span t-field="p.total_estim_weight"/></p>

                                      </td>

                                   <tr t-foreach="p.quant_ids" t-as="q">

                                    <td><p><b>Product Inside: </b><span t-field="q.product_id"/><b>Product Qty: </b><span t-field="q.qty"/>                                      </p></td>

                                     </tr>

                                       </tr>

                                     </tbody>

                                      </table>

                              </t>

                              </t>

                               </t>

with help from Jaydeep Barot, i got below code to work, which might help others looking for help

PACKAGES

Package Name

Package size (LXWXH): XX

Package net_weight: Package gross_weight:

Product Inside: Product Qty:

Nischal
on 10/27/15, 3:27 PM

PACKAGES

Package Name

Package size (LXWXH): XX

Package net_weight: Package gross_weight:

Product Inside: Product Qty:

Nischal
on 10/27/15, 3:30 PM
2
Jaydeep Barot (jar)
On 10/26/15, 8:18 AM

Hello Nischal,

Using this code :

<?xml version="1.0"?>

<t t-name="stock.report_picking_packaging">

<t t-call="report.html_container">

<t t-foreach="docs" t-as="o">

<t t-set="prev" t-value="0" />

<p> <t t-esc="prev"/><b>Prev: </b></p>

<tr t-foreach="o.pack_operation_ids" t-as="n">

<t t-set="new" t-value="n.result_package_id.id" />

<p><t t-esc="new"/><b>new: </b></p>

<p t-if="new != prev"><b>Package name: </b><span t-field="n.result_package_id"/></p>

<t t-set="prev" t-value="n.result_package_id.id" />

<p> <t t-esc="prev"/><b>Prev: </b></p>

<br/>

</tr>

</t>

</t>

</t>


It's display below: 

==============

0Prev:

21 new:

Package name: BOX0018

21 Prev:

20 new:

Package name: BOX0017

20 Prev:

19 new:

Package name: BOX0016

19 Prev:

21 new:

Package name: BOX0018

21 Prev:



=========================================

Here is remove duplicate packages.

=========================================

<h1>PACKAGES</h1>

<table class="table table-condensed" t-if="o.pack_operation_ids">

<thead>

<tr>

<th><strong>Package Name</strong></th>

</tr>

</thead>

<tbody>

<t t-set="package" t-value="list(set([ pack.result_package_id for pack in o.pack_operation_ids if pack.result_package_id]))"/>

<tr t-foreach="package" t-as="p">

<td><span t-esc="p.name"/></td>

</tr>

</tbody>

</table>

Dear jaydeep, I dont want to display the same package twice, for e.g BOX0018. the system does that because of the multiple operations performed with the same package(BOX) and reports it in sequence as performed. While reporting i want it to display the package once but the content inside should be shown below the BOX.

Nischal
on 10/26/15, 5:01 PM

Thanks Jaydeep, using the your updated code i was able to achieve what i was looking for. comment updated

Nischal
on 10/27/15, 3:22 PM
0
Zbik
On 10/24/15, 6:53 AM

Try like this:

<t t-set="FOO" t-value="[1, 2, 3, 1, 2, 5, 1, 5, 6, 7, 8]"/>
<t t-foreach="o.loop_ids" t-as="n">
...
<t t-esc="FOO.append(n.id)"/>
</t>
Result without duplicates: <t t-esc="list(set(FOO))"/>

UPDATED:

<t t-set="FOOX" t-value="list(set(FOO))"/>
<t t-foreach="FOOX" t-as="x">
<t t-esc="x"/>
</t>


If appended ids 328,329, result = [1, 2, 3, 5, 6, 7, 8, 328, 329]


Thanks Zbik, I tried the code below but it gives me same result Box0018 gets duplicated. Did i do something wrong. or should i use the output resulting id's in next iteration(but how) Also if you can please explain me the t-value used in this solution

Prev:

ops_ids:

new:

Package name:

Prev:


Result without duplicates:
Nischal
on 10/24/15, 3:07 PM

t-value is only for example. In the real solution you should use t-value="[]" and FOO ids in next iteration.

Zbik
on 10/26/15, 7:04 AM

Thanks Zbik, But how to use the FOO ids as o.pack_operation_ids in next iteration? it gives me error if i use FOO insted of o.pack_operation_ids.

Nischal
on 10/26/15, 4:50 PM

Answer updated with example

Zbik
on 10/27/15, 6:04 AM

Dear Zbik, I still fail to understand how to use the appended ids available(my apologies as i am not a developer).. The pack_operation_ids gives me value like "stock.pack.operation(id,)" but is just a number(i.e the id). i am not able to use it in the next iteration.

Nischal
on 10/27/15, 3:21 PM

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 10/23/15, 6:05 PM
Seen: 1359 times
Last updated: 10/27/15, 3:35 PM