Search code examples
odooqweb

Add xpath in Odoo qweb report


How in inherit qweb add new element after last paragraph in original report:

<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>

Solution

  • You can find the last p-element in your report by using xpath like this:

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

    The (//p) part finds all p-elements and the filter [position()=last()] selects the last of them.

    I assumed that the p element is in your base report and the xpath-part is in your inherited report.

    Please keep in mind that the p element exists only if your model had data in comment field. The xpath does not know if the last one is the comment or not. It just blindly takes the last one from report and in your example it does not appear in the report if the t-if="o.comment" is not true.

    Hope this helped you.

    Br,

    Veikko