Odoo15: resize invoice logo - reporting

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>

Related

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.

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

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>

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>

How can I create a view without a model in Odoo 10

I just need a basic page to show some static information in a <p> tag. How can I create a form that has no model?
For this you can create a QWeb Report wich are standard web pages.
openacademy/views/report.xml
<template id='template_id'>
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="report.external_layout">
<div class="page">
<h2>Report title</h2>
<p> report text </p>
</div>
</t>
</t>
</t>
</template>
Place the report in the manifest file
openacademy/manifest.py
# always loaded
'data': [
'views/openacademy.xml',
'views/report.xml',
],
Documentation on QWeb Report
The best way to solve this is with simple Odoo MVC. Just create a controller that will render a view; define the view to be rendered and register the view. I found a tutorial here: https://www.odoo.yenthevg.com/creating-webpages-controllers-odoo10/
Note that (as of the time of this posting) the tutorial has an error in the view's XML -- line 16 and 17 need to be swapped so that the XML is nested properly.

Resources