我想根据图像上以下标记的字段对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["uom"] != "Unit(s)"">
<t t-esc="line["uom"]"/>
</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["price_unit"]"/>
<t t-if="line["discount"] != 0">
Disc: <t t-esc="line["discount"]"/>%
</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>
请为同一字段提供代码,并在何处放置代码
假设products
是字典列表,您需要使用Total
(数量 * price_unit)进行排序。
您可以将sorted与t-foreach
一起使用:
<tr t-foreach="sorted(products, key=lambda d: d['quantity']*d['price_unit'])" t-as="line">
如果要反转顺序,请将reverse
参数设置为True
。