Help

2

How to have custom header in qweb report?

Avatar
Yogesh

I need to have headers report specific, I know I can inherit standard header and customize that but it becomes global header, If I inherit header in both reports it prints in one only which loads later ( later report replaces previous header). how can I have report spcific headers?

Avatar
Discard
2 Answers
5
Avatar
Sajin Aziz
Best Answer

  <div class="header">
            This Is Header
  </div>

use it before <div class="page">  in report,

to re-use make it as seperate template. then u can use <t t-call="module_name.template_id"/>

1 Comment
Avatar
Discard
Avatar
Ankit H Gandhi(AHG)
-

Thanks @ Sajin Aziz

6
Best Answer

Hi Yogesh!

You actually have two options. The first is to create a new header template in the module reports, in the file layouts.xml (addons/report/views/layouts.xml). For example:

<template id="your_custom_layout_header">

<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;"/>
<!-- All your custom code here -->

</div>
</div>
</div>

</template>

Which you can then load in your report.

<t t-call="report.your_custom_layout_header">

The second option is to use the header element in Odoo. Before the <div class="page"> tag you can then do this:

<div class="header">
           <h3>Header title</h3>
          <t t-esc="o.name"/>
  </div>

2 Comments
Avatar
Discard
Avatar
Donald Leaman
-

I did it like your second example. But it does not have a separator line under it. I tried <hr> and it wanted </hr> as well. Then I added style of height. It didn't work. How do I get a bold horizontal line at the end of the header?

Avatar
Donald Leaman
-

On the other hand, looking at your first example, I went to /usr/lib/python2.7/dist-packages/odoo/addons/report/views/layout_templates.xml and fount the templates for the odoo-supplied header and footer and used them as examples for my various customized headers and footers for my own various customized reports. Works great!