Add xpath in Odoo qweb report - odoo

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>

Make sure to inherit the template id as below and then after add your xpath. Hope this helps you.
<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>

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

Related

Replace tree view with xpath and context - odoo 14

It´s possible to replace a tree view and use the xpath tag with context?
For example:
<xpath expr="//tree" position="replace" condition="context.get('hide')">
<tree>...tree view...</tree>
</xpath>
Or something similar.

How to print order ref name in pos receipt odoo

I want to add order ref name in receipt.Check my image.
There are multiple ways i.e. by editing from front end, or by extending the template.
Option1: From Front end
Activating Developer Mode.
Then Technical
Then Reports.
Find your desire report and edit it.
Option2: Extending The Template
<template id="report_invoice_document_inherit321" inherit_id="external_id_of_template">
<xpath expr="YOUR_XPATH_WHERE_YOU_WANT_YOUR_OUTPUT" position="after">
</xpath>
</template>

Odoo - Remove internal reference from Sales Order report

I am using Odoo 10 and I dont want the Product Internal Reference(default_code) printing on the Sales order report. I only want to remove from the report so customer cannot see the Internal Reference.
I tried below I seen on another post but it didnt work.
<!-- remove internal reference form Sales report.-->
<template id="sale_order_fields_inherit_saleorder_document" inherit_id="sale.report_saleorder_document">
<strong><span t-field="l.product_id.name"/></strong>
</template>
Inherit the sale_order_document report and replace the l.name with product_id.name here is complete code:
<template id="sale_order_fields_inherit_saleorder_document"
inherit_id="sale.report_saleorder_document">
<xpath expr="//span[#t-field='l.name']" position="replace">
<span t-field="l.product_id.name"/>
</xpath>
</template>
you can try this one !!, may be it'll help you.!

Hide element in inherit qweb odoo 9

Is it possible with xpath exp in inherit qweb hide below line?
<t t-set="doc" t-value="doc.with_context({'lang':doc.partner_id.lang})" />
You have to use replace and you have to identify the correct node. So identify the node and replace it.
<xpath expr="//t[last()]" position="replace">
<!-- <t t-set="doc" t-value="doc.with_context({'lang':doc.partner_id.lang})" /> -->
</xpath>
I usually like to replace it with a commented out version of itself. Also the above will only work if the t tag is the last in the document.
You may have to capture a parent node and inject all of the existing xml with your desired t element commented out or removed. You may also be able to use these expressions or some variation of them.
expr="//div[#name='div_name']/t"
expr="//div[#name='div_name']/t[first()]"

qweb t-if in position attribures

I am developing a module in Odoo. I need to change the report of invoice to add some details.
I use xpath with position attribute and check if an affair is linked to hide the default table.
<template id="my_invoice" inherit_id="account.report_invoice_document">
<xpath expr="//div[#class='page']/table[#class='table table-condensed']" position="attributes">
<attribute t-if="o.affair_id" name="class">hidden</attribute>
</xpath>
</template>
This is not working. The default table is hidden in every invoices even if the invoice is not linked to an affair.
I do not understand because the condition works in my second template.
<template id="my_invoice2" inherit_id="account.report_invoice_document">
<xpath expr="//div[#class='page']/div[#class='row mt32 mb32']" position="after">
<t t-if="o.affair_id">
<!-- table with my additional detail -->
</t>
</xpath>
</template>
Sorry for my english. I am learning it.
try this one:
<attribute name="t-att-style">'display: none;' if o.affair_id else ''</attribute>
OR even this one also:
<attribute name="t-att-class">'hidden' if o.affair_id else ''</attribute>
it may help in your case.