首页 > 解决方案 > 如何在 RML-Odoo v8 中使用“if 条件”

问题描述

我想使用条件根据设置的值打印某些条款和条件。

例如,付款有 10 个“条款和条件”。默认速率为“rate1”,但如果选择“rate2”,则条件 3 和 4 应更改为其他值。

如果设置了“rate1”,则

1. This is condition for both (1 or 2)
2. This is condition for both (1 or 2)
3. This is condition for rate 1
4. This is condition for rate 1
.
.
.
9. This is condition for both (1 or 2)
10. This is condition for both (1 or 2)

如果设置了“rate2”,则

1. This is condition for both (1 or 2)
2. This is condition for both (1 or 2)
3. This is condition for rate 2
4. This is condition for rate 2
.
.
.
9. This is condition for both (1 or 2)
10. This is condition for both (1 or 2)

条款和条件是“静态的”,不存储在对象中。

我的 RML 是这样的:

<tr>
    <td><para>1</para></td>
    <td><para>This is condition for both (1 or 2)</para></td>
</tr>
<tr>
    <td><para>2</para></td>
    <td><para>This is condition for both (1 or 2)</para></td>
</tr>
<tr>
    <td><para>3</para></td>
    <td><para>This is condition for rate 1</para></td>
</tr>

有什么方法可以在第 3 行使用“条件”。

先感谢您。

标签: odoo-8rml

解决方案


我不确定它在 RML 中是否完全具有“if else 条件”。

但就我而言,我设法解决了以下问题,并且可能对像我这样的人有所帮助。

[[ r.rate2 != '']]
[['3. Condition for Rate 2 '']]
[[ r.rate1 != '']]
[['3. Condition for Rate 1 '']]

或者

[[(r.rate1 == 0 and ' ') or '3. Condition for Rate 1']]
[[(r.rate2 == 0 and ' ') or '3. Condition for Rate 2']]

这似乎不是一个好方法,但解决了问题。

如果找到更好的方法,将永远不胜感激。


推荐阅读