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>
Related
I want to create a qweb report that shows all tickets related to a product:
This is what I have:
<report id="website_helpdesk_support_ticket.print_support_request"
model="helpdesk.support"
report_type="qweb-pdf"
string="Ticket"
name="website_helpdesk_support_ticket.support_report"
file="website_helpdesk_support_ticket.support_report"/>
<template id="website_helpdesk_support_ticket.support_report">
<t t-foreach="docs" t-as="doc">
<t t-call="web.external_layout">
<h1>Information about the ticket:</h1>
<span t-field="doc.product.default_code"/>
...
<h1>Related Tickets</h1>
<t t-foreach="docs.filtered(lambda x: x.product.barcode == doc.product.barcode)" t-as="related_ticket">
<span t-field="related_ticket.request_date"/>
</t>
</t>
</t>
</template>
But it shows only 1 ticket.
Thank you
your code should be as following:
<template id="website_helpdesk_support_ticket.support_report">
<t t-foreach="docs" t-as="doc">
<t t-call="web.external_layout">
<h1>Information about the ticket:</h1>
<span t-field="doc.product.default_code"/>
...
<h1>Related Tickets</h1>
<t t-foreach="docs.filtered(lambda x: x.product.barcode == doc.product.barcode)" t-as="related_ticket">
<span t-field="related_ticket.request_date"/>
</t>
</t>
</t>
</template>
<template id="support_ticket_report">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="o">
<t t-set="lang" t-value="o.user_id.lang"/>
<t t-call="website_helpdesk_support_ticket.support_report" t-lang="lang"/>
</t>
</t>
</template>
<report id="website_helpdesk_support_ticket.print_support_request"
model="helpdesk.support"
report_type="qweb-pdf"
string="Ticket"
name="website_helpdesk_support_ticket.support_ticket_report"
file="website_helpdesk_support_ticket.support_ticket_report"/>
Solved it with:
p_tickets = fields.Many2many('helpdesk.support', 'product_ticket_rel', 'product_id', 'ticket_id', string='Tickets')
<t t-foreach="docs.product.p_tickets" t-as="related_ticket">
<span t-field="related_ticket.request_date" t-options ='{"format": "dd/MM/yyyy"}'/>
</t>
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>
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.
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>
Hi Friends I have used Qweb to generate the pdf report in odoo 9 now i can download the pdf file but the file does not showing the data
Generated PDF
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="report_invoice">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="report.external_layout">
<div class="page">
<div class="row">
<h2 class="text-center" style="font-size: 24px;font-weight: bold;">company </h2>
<p>This object's name is <span t-field="o.name"/></p>
</div>
</div>
</t>
</t>
</t>
</template>
</odoo>
i have changed the return of the function which will print the pfd it worked for me
return {
'type': 'ir.actions.report.xml',
'report_name': 'module.report_invoice',
'datas': datas,
}