Odoo 12 report sample - odoo

I am trying to make a report but without using external_layout or internal_layout because they have headers in them. I wanted to have my own header and footer.
I have tried using minimal_layout because it seems it is the less busy layout compared to other layouts.
But I kept having error body_parent = root.xpath('//main')[0] IndexError: list index out of range - - -
Here is my code
<template id="applicant_contract_css">
<t t-call="web._assets_helpers"/>
<link rel="stylesheet" type="text/scss" href="/fhid_recruitment/static/src/css/applicant-contract.css"/>
</template>
<template id="minimal_layout" inherit_id="web.minimal_layout">
<xpath expr="//head" position="inside">
<t t-call-assets="fhid_recruitment.applicant_contract_css"/>
</xpath>
</template>
<template id="applicant_contract_offering">
<t t-call="web.minimal_layout">
<t t-foreach="docs" t-as="o">
<div class="header">
My Header
</div>
<div class="article">
Content
</div>
<div class="footer">
My footer
</div>
</t>
</t>
</template>
How do I use minimal layout? or is there another layout should I use?

When you want create a template report you need to at least call, "web.html_container" witch call "web.report_layout" witch define Minal Report layout .
all css file for report template should be add to report_assets_common template:
<template id="assets_common" name="a proper name for your template purpuse" inherit_id="web.report_assets_common">
<xpath expr="." position="inside">
<link rel="stylesheet" type="text/scss" href="/fhid_recruitment/static/src/css/applicant-contract.css"/>
</xpath>
</template>
It's better to extract your header and footer to template so you use them in multiple report, like the external_layout, you can take a look at the external_layout_standard to get the basic Idea.
<template id="external_layout">
<div class="header">
My Header
</div>
<!-- everything inside t-call="fhid_recruitment.external_layout" will be rendered here -->
<t t-raw="0" />
<div class="footer">
My footer
</div>
</template>
In the template just call your custom external layout here:
<template id="applicant_contract_offering">
<t t-call="web.html_container">
<!-- because it's defined in this module "fhid_recruitment" -->
<t t-call="fhid_recruitment.external_layout">
<t t-foreach="docs" t-as="o">
<div call="page">
<div class="article">
Content
</div>
</div>
</t>
</t>
</t>
</template>
One of the most import thing you need to know about template is the <t t-raw="0" />, if for example a template x_template have this when we call it like this:
<t t-call="x_template">
any_content
</t>
what the Qweb engine will do is, replace <t t-raw="0" /> inside the x_template with any_content when rendering the report.
To simplify things if you are going to use header and footer only for one template:
<template id="applicant_contract_offering">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="o">
<div class="header">
My Header
</div>
<div class="article">
Content
</div>
<div class="footer">
My footer
</div>
</t>
</t>
</template>

You can inherit either external_layout or internal_layout and override the default behaviour with your custom code. And use it in your report.

Related

Call template odoo

I create template in module labs.
<template id="worbook_employee_miss_message">
<t t-if="time_research">
<div>
<span style="color: red">test</span>
</div>
</t>
</template>
I call it in formview
<t t-call="labs.worbook_employee_miss_message">
<t t-set="time_research" t-value="time_research"/>
</t>
But there is no block div on form. time_research field is not empty.
I tried your code and it's ok. Be sure to call the template inside a
<div class="page">
</div>

Barcode not showing up

<template id="report_label">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<div class="page">
<div class="row">
<div class="example_class">
<t t-esc="o.name" />
<t t-esc="o.type" />
<p>Size: <span t-esc="o.calculate_size()"/></p>
<p>Color: <span t-esc ="o.calculate_color()" /></p>
<p>Price: </p>
<tr><td colspan="2"><img t-att-src="'/report/barcode/Code128/%s' % 'test-0001'" style="width:100%;height:25px"/> </td></tr>
</div>
</div>
</div>
</t>
</t>
</template>
this is my template and for some reason, barcode is not showing up.
if I test in http://localhost:8069/report/barcode/Code128/test-0001 then it returns me a barcode.
and reportlab is also installed.
same result but smaller borders with
<img t-if="o.barcode" t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' %('Code128',o.barcode,250,50)"/>
is Settings > System Parameters need to change
Key report.url
Value http://0.0.0.0:8069

Odoo - page number in qweb reports

I am working with qweb reports in odoo 10 . Here is what i did
<odoo>
<template id="report_customer">
<t t-call="report.html_container">
<t t-set="data_report_margin_top" t-value="50"/>
<t t-foreach="range(5)" t-as="1">
<t t-foreach="docs" t-as="o">
<t t-call="report.internal_layout">
<div class="page example-css-class">
<h2>Report title</h2>
<p>This object's name is
<span t-field="o.full_name"/>
</p>
<ul class="list-inline">
<li>Page:</li>
<li><span class="page"/></li>
<li>/</li>
<li><span class="topage"/></li>
</ul>
</div>
</t>
</t>
</t>
</t>
</template>
</odoo>
and i also tried this
<odoo>
<template id="report_customer">
<t t-call="report.html_container">
<t t-set="data_report_margin_top" t-value="50"/>
<t t-foreach="range(5)" t-as="1">
<t t-foreach="docs" t-as="o">
<t t-call="report.internal_layout">
<div class="page example-css-class">
<h2>Report title</h2>
<p>This object's name is
<span t-field="o.full_name"/>
</p>
<div class="footer" style="text-align: center !important;">
Page <span class="page"/> of <span class="topage"/>
</div>
</div>
</t>
</t>
</t>
</t>
</template>
</odoo>
but in both cases i am not able to see page numbers. I also tried adding custom header and footer in separate templates but that also doesn't work.
Try this :
<div class="footer">
<div class="row">
<center><span>Page </span><span class="page" /> of <span class="topage" /></center>
</div>
</div>
It works perfectly for me.
Note : I have used without calling report.external_layout
Please try this code for page number in Qweb-report. It will automatically display page no.
<t t-call="report.external_layout"></t>

Inherit sale order report in odoo 10

I have tried to add a new page beginning of sale order report by inherit and xpath. But it not work.
Here is the code:
<template id="report_saleorder_inherit" inherit_id="sale.report_saleorder">
<xpath expr="//t[#t-call='report.html_container']" position="before">
<t t-call="report.html_container">
<t t-call="report.external_layout">
<div class="page">
<h1>New Page</h1>
</div>
</t>
</t>
</xpath>
But i edited in core module Sale like below and it works.
<template id="report_saleorder">
<t t-call="report.html_container">
<t t-call="report.external_layout">
<div class="page">
<h1>New Page</h1>
</div>
</t>
</t>
<t t-call="report.html_container">
<t t-foreach="docs" t-as="doc">
<t t-call="sale.report_saleorder_document" t-
lang="doc.partner_id.lang"/>
</t>
</t>
</template>
How can i achieve this in my custom module?
Add dependency of "sale" module in your module and try below code
<template id="report_saleorder_inherit" inherit_id="sale.report_saleorder">
<xpath expr="t" position="before">
<t t-call="report.html_container">
<t t-call="report.external_layout">
<div class="page">
<h1>New Page</h1>
</div>
</t>
</t>
</xpath>
</template>

How to display the company header only on the first page?

i want to show the company reportheader only on the first page.I have now beautifull qweb report in PDF. But if my reports (sale order, for example) have more than one page, the header is on EACH page.
How to put company header only on the first page?
Thanks,
Header is only displayed once, in first page.report. The others are empty
<template id="report_quotation_header" inherit_id="report.external_layout_header">
<xpath expr="//div[#class='header']" position="replace">
<div class="header">
<t t-set="data_report_margin_top" t-value="12"/>
<t t-set="data_report_header_spacing" t-value="9"/>
<t t-set="data_report_dpi" t-value="110"/>
<div class="row">
<div class="col-xs-3" name="company_address">
<div t-field="company.partner_id"
t-field-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": true}'
style="border-bottom: 1px solid black;"/>
</div>
</div>
</div>
</xpath>
</template> <!-- end teamplate header-->
Call your header inside page div. This will print header only on first page of qweb report in odoo
in odoo 10 I have done this as follows:
<template id="custom_report_header" inherit_id="report.external_layout_header" primary="True">
<xpath expr="//div[#class='header']" position="replace">
<div class="header">
<div class="row">
<div class="col-xs-3">
<img t-if="company.logo" t-att-src="'data:image/png;base64,%s' % company.logo" style="max-height: 45px;"/>
</div>
<div class="col-xs-9 text-right" style="margin-top:20px;" t-field="company.rml_header1"/>
</div>
<div class="row zero_min_height">
<div class="col-xs-12">
<div style="border-bottom: 1px solid black;"></div>
</div>
</div>
</div>
</xpath>
</template>
<template id="your_custom_header_id" inherit_id="report.external_layout" primary="True">
<xpath expr="//t[#t-call='report.external_layout_header']" position="replace">
<t t-call="your_module_name.custom_report_header" />
</xpath>
</template>
<template id="your_report_name"
<t t-call="report.html_container">
<div class="page">
<t t-call="your_module_name.your_custom_header_id">
</t>
....
</div>
</t>
</template>
pramod24
You can use the OCA App Report Qweb Element Page Visibility.
You can use this class first-page shows an element only on the first page.
Thanks