How xpath can search with class name of a div(s) - odoo-11

How to search for all DIVs with a specific class name via xpath
I'm currently using the following code:
<template id="external_layout_boxed" inherit_id="web.external_layout_boxed">
<xpath expr="//div[#class='header']" position="replace">
<t>
xxxxxx
</t>
</xpath>
</template>

Searching through all the Odoo plugins I finally found the answer :
<template id="external_layout_boxed" inherit_id="web.external_layout_boxed">
<xpath expr="//div[hasclass('header')]" position="replace">
<t>
xxxxxx
</t>
</xpath>
</template>

Related

Odoo15: resize invoice logo

I need to change size of logo on invoice header only. At first attempt I tried this for selected layout:
<template id="external_layout_bold_ksp" inherit_id="web.external_layout_bold">
<xpath expr="//div[#t-attf-class='header o_company_#{company.id}_layout']/div/div/div/img"
position="replace">
<img t-if="company.logo" style="max-width: 350px;max-height: 190px;"
t-att-src="image_data_uri(company.logo)" alt="Logo"/><br/>
</xpath>
</template>
it worked but it is changing all logos of all pdf reports for bold layout, unable to find logo path in report template report_invoice_document. I need to resize only invoice report's logo
I have applied something like that in Odoo 11 and it will work on other versions.
To resize the logo in invoice report only, you need to pass value through context from invoice report and then check it in the external layout bold template.
I have added change_logo_size Boolean context value from invoice report and set it to true as below:
<template id="report_invoice_document_logo" inherit_id="account.report_invoice_document">
<xpath expr="//t[#t-call='web.external_layout']" position="before">
<t t-set="o" t-value="o.with_context(change_logo_size= True)"/>
</xpath>
</template>
hen in the inheritance of external layout bold, I have checked the value from the context and if it's true then apply the replace for image, otherwise leave it as its:
<template id="external_layout_bold_ksp" inherit_id="web.external_layout_bold">
<xpath expr="//div[#t-attf-class='header o_company_#{company.id}_layout']/div/div/div/img" position="replace">
<t t-if=" o and o.env and 'change_logo_size' in o.env.context and o.env.context.get('change_logo_size',False)">
<img t-if="company.logo" style="max-width: 350px;max-height: 190px;"
t-att-src="image_data_uri(company.logo)" alt="Logo"/>
</t>
<t t-else="">
<img t-if="company.logo" t-att-src="image_data_uri(company.logo)" alt="Logo"/>
</t>
</xpath>
</template>

Odoo xpath expression rule

I'm developing a Qweb report in Odoo and I need to use xpath expressions for replacing some content.
This is the main template where is needed to make the replace of the content:
<template id="report_saleorder2_template">
<t t-name="report_saleorder2_template">
<t t-call="web.external_layout">
<div class="page">
<div class="oe_structure" />
<div class="row" id="report_data_0">
<h1>Annual voluntary contribution to Fecoas - Alcaste school</h1>
//more code
This is the other template where I'm tying to use the xpath expression for replacing the content:
<template id="report_saleorder3_template">
<t t-name="report_saleorder3_template">
<t t-call="custom_v12_reports.report_saleorder2_template" t-lang="doc.partner_id.lang" />
<xpath expr="//div[#id='report_data_0']/h1[1]" position="replace">
<h1>Annual AMPA's member fee Alcaste school</h1>
</xpath>
</t>
</t>
</template>
This is not working. Someone knows why?
Thanks for reading!
You have to inherit the origin template with inherit_id. Then you're able to use XPath expressions to change or add new code.
<template id="report_saleorder3_template"
inherit_id="module_name.report_saleorder2_template">
<xpath expr="//div[#id='report_data_0']/h1[1]" position="replace">
<h1>Annual AMPA's member fee Alcaste school</h1>
</xpath>
<!-- and other XPath expressions -->
</template>

How to set font size or bold on description record row on Qweb sale report?

<?xml version="1.0" encoding="utf-8"?><odoo> <data>
<template id="id_document" inherit_id="sale.report_saleorder_document">
<xpath expr="//tbody[#class='sale_tbody']//tr//td[1]" position="replace">
<t t-esc="layout_category['name']" style="font-weight: bold;"/>
</xpath>
</template> </data></odoo>
the following code doesn't work for me,please any suggestion thanks
Got a solution
<xpath expr="//div[hasclass('row','mt32','mb32')]/div[#t-if='doc.user_id.name']/p" position="attributes">
<attribute name="style">font-weight: bold;color:red;</attribute>
</xpath>
You can not use style attribute in <t t-esc> tag.
If you want to use style attribute then you must need to use any HTML tag like div, p, span
Here is an example.
<span style="font-weight: bold;"><t t-esc="layout_category['name']"/></span>
Try to use above code. Hope it will work fine. Upvote if the suggestion is working.

Xpath in current view with inherit_id

I'm using Odoo V12 CE and my issue is I try to edit a PageA view.
Have some PageA, PageB and more, inherit ParentPage.
I want to inherit ParentPage into PageA to add some content and, PageB must be: PageB = ParentPage(without modifications from PageA) + PageB.
Helps please and thanks for all!!
<template id="tpml_id" inherit_id="parent.tpml_parent_id" name="Posts">
<xpath expr="//ul[#id='post-list']" position="after">
<span>This is my posts list for all page (MyPage and all page inherits ParentPage). It's so bad. </span>
</xpath>
</template>
<!-- I want this -->
<template id="tpml_id" copy_inherit_id="parent.tpml_parent_id" name="Posts">
<xpath expr="//ul[#id='post-list']" position="after">
<span>This is my post list for this page only. </span>
</xpath>
</template>
If you want to inherit view but do not want to add anything in parent.tpml_parent_id then you can write as following :
<template id="tpml_id" inherit_id="parent.tpml_parent_id" name="Posts" primary="True">
<xpath expr="//ul[#id='post-list']" position="after">
<span>This is my post list for this page only. </span>
</xpath>
</template>

internal reference of the product did not add to the invoice report in odoo 10

I add internal reference of product to the sale form and I want it in the invoice report also
the sale code is :
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
_name = 'sale.order.line'
x_field = fields.Float('Unit cost')
internal_ref=fields.Char(related='product_id.default_code',string='Internal
reference product',store=True,default=100)
partner_name=fields.Many2one('res.partner','partner_id.name')
this is my code but did not work
the python code:
class invoiceLineField(models.Model):
_inherit='account.invoice.line'
internal_ref=fields.Char(related='product_id.default_code',string='Internal
reference product',store=True)
and this is xml report:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="report_invoice_document_itemnumber"
inherit_id="account.report_invoice_document">
<xpath expr="//div[contains(#class, 'page')]/table[1]/thead/tr/th[1]"
position="before">
<th>Internal reference</th>
</xpath>
<xpath expr="//div[contains(#class, 'page')]/table[1]/tbody/tr/td[1]"
position="before">
<td>
<span t-field="l.internal_ref"/>
</td>
</xpath>
</template>
</data>
</odoo>
no error but the internal reference of product did not appear in the result
If you want the 'default_code' field just to print in report then you can achieve it by 'product_id.default_code'.
<span t-field="l.product_id.default_code"/>

Resources