reporting - 在 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["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
(quantity * price_unit)进行排序。
您可以使用排序t-foreach
:
<tr t-foreach="sorted(products, key=lambda d: d['quantity']*d['price_unit'])" t-as="line">
如果要颠倒顺序,请将reverse
参数设置为True
。
推荐阅读
- java - O(n) 中的好对数
- html - 需要帮助了解适合内容
- karate - 如何将元素的文本值存储在空手道的变量中?
- angular - “对象”类型上不存在属性“大小”
- r - 不要如何转换为“POSIXct”类
- flutter - FlatButton 没有任何按压效果/动画
- browser - 在浏览器上实现证书认证
- discord - 设置链接MessageEmbed,Discord js时未定义
- virtualbox - 如何在 Virtualbox 中将新硬盘附加到 Minikube?
- javascript - 如何使用 forEachFeatureAtPixel() 在叠加中显示 2 个不同图层的要素数据