How to link custom paper format in QWEB Reports - BOOKC -->

How to link custom paper format in QWEB Reports

Wednesday, September 12, 2018

In this tutorial I am going to show you how to add or link custom paper format in your newly/existing QWEB Reports. Before adding or linking custom paper format in QWEB reports I want to tell you why we need this custom paper format.



custom paper format in QWEB Reports

Why we need custom paper format

The purpose of adding custom format to your QWEB reports is that you can set format, page_height, page_width, orientation, margin_top, margin_bottom, margin_left, margin_right, header_line, header_spacing and dpi as per your need or requirement. Below is the code for custom paper format.

    
    <report
        id="report_monthly_pensioners"
        model="dgmsw.employee.salary"
        string="Monthly Report"
        name="dgmsw.monthly_report"
        file="dgmsw.report_monthly_pensioners"
        report_type="qweb-pdf" />

    <record id="paperformat_low_monthly_report" model="report.paperformat">
        <field name="name">PF Monthly Report</field>
        <field name="default" eval="True"/>
        <field name="format">A4</field>
        <field name="page_height">0</field>
        <field name="page_width">0</field>
        <field name="orientation">Portrait</field>
        <field name="margin_top">10</field>
        <field name="margin_bottom">15</field>
        <field name="margin_left">7</field>
        <field name="margin_right">7</field>
        <field name="header_line" eval="False"/>
        <field name="header_spacing">3</field>
        <field name="dpi">90</field>
    </record>
    <record id="dgmsw.report_monthly_pensioners" model="ir.actions.report.xml">
      <field name="paperformat_id" ref="dgmsw.paperformat_low_monthly_report" />
    </record>      
 

Here we will mention the name of paper format, this could be any meaningful name.

<field name="name">PF Monthly Report</field>       
 

Format of the paper (A0 to A9, B0 to B10, Legal, Letter, Tabloid etc) goes here. A4 by default.

<field name="format">A4</field>      
 

By default it value is 0, but can change it according to your template.

<field name="page_height">0</field>
<field name="page_width">0</field>      
 

The value of orientation will be Portrait or Landscape.

<field name="orientation">Portrait</field>       
 

As name shows margin_top will set the space or margin from top and margin_bottom will add or set space from bottom. Here one more point need to be noted that when you call the external_layout report template for your QWEB reports than sometimes in pdf it does not shows header or footer in proper format. To overcome this issue you just need to increase top or bottom margin.

<field name="margin_top">10</field>
<field name="margin_bottom">15</field>       
 

This will set margin on left and right.

<field name="margin_left">7</field>       
<field name="margin_right">7</field>      
 

By using this you can increase or decrease space between header and page according to your need.

<field name="header_spacing">3</field>      
 

The default is 90 DPI with Odoo, but the DPI resolution can be changed.

<field name="dpi">90</field>       
 

Now we have successfully linked our custom paper format with odoo qweb report.

custom paper format in QWEB Reports

ParseError: "report.paperformat" while parsing


If you face above error while upgrading your module than follow below steps.
1- Open __openerp__.py file
2- Add module name 'report' in depends just like below.

'depends': ['report'],      
 

Now restart your odoo server and upgrade your module again.