首页 > 解决方案 > 在 POS_Sale_detail 报表中对 Qweb 报表行进行数字排序

问题描述

我想根据下面标记的字段对 qweb 报告从降序到升序进行排序,在图像上 输入图像描述

报表的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>

请提供相同字段的代码,以及放置代码的位置

标签: reportingodoo-11

解决方案


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

您可以使用排序t-foreach

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

如果要颠倒顺序,请将reverse参数设置为True


推荐阅读