首页 文章

在Odoo qweb报告中添加xpath

提问于
浏览
0

如何继承qweb在原始报告的最后一段后添加新元素:

<p t-if="o.comment">
    <strong>Comment:</strong>
    <span t-field="o.comment"/>
</p>

//add after <p t-if="o.comment">
<xpath expr="??" position="after">
     <p>new</p>
</xpath>

2 回答

  • 3

    您可以使用xpath在报告中找到最后一个p元素,如下所示:

    <xpath expr="(//p)[position()=last()]" position="after">

    (//p) 部分找到所有p元素,过滤器 [position()=last()] 选择最后一个 .

    我假设p元素在您的基本报告中,而xpath-part在您的继承报告中 .

    请记住,只有当您的模型在注释字段中包含数据时,才会存在p元素 . xpath不知道最后一个是否是注释 . 它只是盲目地从报告中获取最后一个,并且在您的示例中,如果 t-if="o.comment" 不为真,它不会出现在报告中 .

    希望这对你有所帮助 .

    BR,

    韦科

  • 3

    确保继承模板ID,如下所示,然后添加xpath . 希望这对你有所帮助 .

    <template id="report_saleorder_inherit" inherit_id="report.external_layout_footer">
        <xpath expr="//p[@t-if='o.comment']" position="after">
            <p>new</p>
        </xpath>
    </template>
    

相关问题