python - Odoo 9 qweb float 除以零

标签 python report odoo odoo-9 qweb

在下面的 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/

相关文章:

python - 更新我的 NVIDIA 版本过时错误

ios - CFNetwork/AppleJPEG 崩溃

postgresql - Postgres 查询 GROUP BY

python - cr.execute在OpenERP开发中是什么意思?

python - 不理解不同算法之间计算复杂度的差异

Python 多处理和导入模块

Python - 从 pandas 的聚合结果中获取组名称

sql - 将单个查询结果添加到JMeter报告中

c# - 以编程方式生成带有设计的 PDF 报告

python - 从发票 openerp 生成拣货