Odoo 如何使用t-if生成行号中的条件
我试图在odoo 11中修改报表发票中的一行,在点击“打印”按钮进行打印后,我需要关于报表生成的行数的条件Odoo 如何使用t-if生成行号中的条件,odoo,qweb,Odoo,Qweb,我试图在odoo 11中修改报表发票中的一行,在点击“打印”按钮进行打印后,我需要关于报表生成的行数的条件 <t-if="number_line_in_table== 1"> <!--DO something..--> </t> 我不认为您可以使用Python风格的枚举,但您可以使用一个老式计数器,如下所示 <t t-set="counter" t-value="0"/> <t t-foreach="records" t-as="re
<t-if="number_line_in_table== 1">
<!--DO something..-->
</t>
我不认为您可以使用Python风格的
枚举
,但您可以使用一个老式计数器,如下所示
<t t-set="counter" t-value="0"/>
<t t-foreach="records" t-as="record">
<t t-set="counter" t-value="counter + 1"/>
<t t-if="counter == 1">
<!-- Do Something. -->
</t>
</t>
如何使用计数器
免责声明:我以前没有这样做过。它可能会也可能不会完全像这样工作。如果无法通过继承使其正常工作,则可以在必要时通过xpath
替换整个foreach
循环
谢谢,但我使用外部xml文件:foreach在odoo xml文件中,我的模块包含继承odoo报告xml文件的xml文件,因此在我的xml文件中,我没有foreach标记来使用您的示例,并且我不应该修改odoo/Add中的xml文件您从core继承了哪个xml文件?继承\u id=“purchase.report\u purchaseorder\u document”和您使用的是哪个Odoo版本?Odoo 11,我需要设置一个条件(t-if),但我需要确定行值编号和当前迭代编号?我发现我们可以使用$as\u索引和$as\u大小,但在t-if示例中如何使用它?
<tr t-foreach="o.order_line" t-as="line">
<td>
<span t-field="line.name"/>
</td>
<td>
<span t-esc="', '.join(map(lambda x: x.name, line.taxes_id))"/>
</td>
<td class="text-center">
<span t-field="line.date_planned"/>
</td>
<td class="text-right">
<span t-field="line.product_qty"/>
<span t-field="line.product_uom.name" groups="product.group_uom"/>
</td>
<td class="text-right">
<span t-field="line.price_unit"/>
</td>
<td class="text-right">
<span t-field="line.price_subtotal"
t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
</td>
</tr>
<xpath expr="//tr[@t-foreach='o.order_line']" position="before">
<t-set="counter" t-value="0"/>
</xpath>
<xpath expr="//tr[@t-foreach='o.order_line']/td[1]" position="before">
<t-set="counter" t-value="counter + 1"/>
<t t-if="counter == 1">
<!-- Do Something. -->
</t>
</xpath>