将Qweb报告行在POS_Sale_detail报告中按数字排序

问题描述 投票:0回答:1

我想根据图像上以下标记的字段对qweb报告从降序到升序进行排序enter image description here

报告的xml代码如下,该表必须根据以粗体显示的字段进行排序

产品

        <table class="table table-condensed">

            <thead><tr>

                <th>Product</th>

                <th>Quantity</th>

                <th>Cost Price</th>

                <th>Total Cost </th>

                <th>Price Unit</th>

                <th>Amount without VAT</th>

                <th>VAT</th>

                <th>VAT Amount</th>

                <th>Total Amount</th>

            </tr></thead>

            <tbody>

               <tr t-foreach="products" t-as="line">

                   <td>

                       <t t-esc="line['product_name']"/>

                       <td>

                       <t t-esc="line['quantity']"/>

                       <t t-if="line[&quot;uom&quot;] != &quot;Unit(s)&quot;">

                       <t t-esc="line[&quot;uom&quot;]"/> 

                       </t>

                       </td>

                       <td>

                       <t t-esc="'%.2f'%(request.env['product.product'].browse(line['product_id']).standard_price)"/>

                       </td>

                       <td>

                       <t t-esc="'%.2f'%(line['quantity']*request.env['product.product'].browse(line['product_id']).standard_price)"/>

                       </td>                  

                       <td>

                       <t t-esc="'%.2f'%line[&quot;price_unit&quot;]"/>

                       <t t-if="line[&quot;discount&quot;] != 0">

                       Disc: <t t-esc="line[&quot;discount&quot;]"/>%

                       </t>

                       </td>

                       <td>

                       <t t-esc="'%.2f'%((line['quantity']*line['price_unit'])/1.05)"/>

                       </td>

                       <td>

                       5%

                       </td>

                       <td>

                       <t t-esc="'%.2f'%(((line['quantity']*line['price_unit'])/1.05)*0.05)"/>

                       </td>

                       ****<td>
                       <t t-esc="'%.2f'%(line['quantity']*line['price_unit'])"/>
                       </td>****

            </tr>

            </tbody>

        </table>

请为同一字段提供代码,并在何处放置代码

reporting odoo-11
1个回答
0
投票

假设products是字典列表,您需要使用Total (数量 * price_unit)进行排序。

您可以将sortedt-foreach一起使用:

<tr t-foreach="sorted(products, key=lambda d: d['quantity']*d['price_unit'])" t-as="line">

如果要反转顺序,请将reverse参数设置为True

© www.soinside.com 2019 - 2024. All rights reserved.