【问题标题】:Add xpath in Odoo qweb report在 Odoo qweb 报告中添加 xpath
【发布时间】:2018-04-13 14:08:03
【问题描述】:

如何继承 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>

【问题讨论】:

    标签: odoo qweb


    【解决方案1】:

    确保继承下面的模板 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>
    

    【讨论】:

      【解决方案2】:

      您可以像这样使用 xpath 找到报告中的最后一个 p 元素:

      &lt;xpath expr="(//p)[position()=last()]" position="after"&gt;

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

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

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

      希望这对您有所帮助。

      兄弟,

      威科

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多