在下面的 qweb 报告中,如果折扣不为 0,则如何设置折扣为 0 的条件。
<td class="text-right">
<span t-esc="l.price_unit-(l.price_unit/l.discount)"/>
</td>
<td class="text-right">
<span t-field="l.quantity"/>
</td>
<td class="text-right">
<span t-field="l.price_unit"/>
</td>
<td t-if="display_discount" class="text-right" groups="sale.group_discount_per_so_line">
<span t-field="l.discount"/>
</td>
<td class="text-right">
<span t-esc="l.price_unit-(l.price_unit/l.discount)"/>
</td>
</tr>
如果折扣为0
<td class="text-right">
<span t-esc="l.price_unit"/>
</td>
艾莉芙
<td class="text-right">
<span t-esc="l.price_unit-(l.price_unit/l.discount)"/>
</td>
有什么简单的解决方案吗?
最佳答案
请查看 official documentation用于 qweb 模板引擎。那里有一个名为 t-if
在您的情况下,这应该有效:
<t t-if="l.discount == 0">
<td class="text-right">
<span t-esc="l.price_unit"/>
</td>
</t>
<t t-if="l.discount != 0">
<td class="text-right">
<span t-esc="l.price_unit-(l.price_unit/l.discount)"/>
</td>
</t>
目前还没有 else 运算符,因此您必须使用两个连续的 if
编辑:在 v10 上,已创建了一个可供您使用的 t-else
运算符。
关于python - Odoo 9 qweb float 除以零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41740042/