Meet Us at GITEX Stand #SRE-22, Sheikh Rashid Hall, India Pavilion

Schedule Meeting
      +91-79-2975-0867,+91-903-347-2982,+91-987-935-4457   contact@serpentcs.com

Guide to convert RML Reports to Webkit Reports!

OpenERP is one of the largest Open Source ERP solutions. It comes with number of reporting tools like RML, Webkit and Aeroo a s an integral part of activity management for any company. OpenERP is flexible to integrate with other reporting engines such as Jasper, BIRT reports.

Why Webkit report?

In most of the official addons, OpenERP uses RML report engine to generate report. But there are plenty of features which lets you be a fan of Webkit repor t.
  • Generates PDF reports from the mako template.
  • HTML like template.
  • CSS can be use to shine the report.
  • Possible to use basic java script.
  • Easy to develop and design.
  • Faster parsing.
  • Paper size definition
  • Multi header support

Basic Requirements to create Webkit report

Module report_webkit will be required to make or convert Webkit reports. Wkhtmltopdf is required to generate mako template in pdf, to get the debian based distribution visit Google wkhtmltopdf project . And download wkhtmltopdf-i386 binary version. Do not download apha version or wkhtmltoimage .

The Basic File Structure Difference Between RML and Webkit Report

 RML Report
Webkit Report
  • __init__.py
  • __openerp__.py
  • rml_report.py
  • report_template.sxw
  • rml_template.rml
  • __init__.py
  • __openerp__.py
  • webkit_report.py
  • webkit_template.mako

Structure Difference Between RML Template & Webkit(mako) template.

While converting RML report to Webkit report you need to do few changes which are highlighted in below,
File RML Webkit
__init__.py import sale_order
import sale_order
__openerp__.py {
    'name': 'Demo Report',
    'version': '1.0',
    'category': 'Demo Module ',
    'sequence': 1,
    'summary': 'Demo Report',
    'description': """
    Module Description
    """,
    'author': 'Serpent Consulting Services', 
    'website': 'www.serpentcs.com',
    'depends': ['base'],
    'data': [
    'report.xml',
    ],
    'installable': True,
    'application': True,
    'auto_install': False,
}
 {
    'name': 'Demo Report',
    'version': '1.0',
    'category': 'Demo Module ',
    'sequence': 1,
    'summary': 'Demo Report',
     'description': """
     Module Description
    """,
    'author': 'Serpent Consulting Services',
    'website': 'www.serpentcs.com',
    'depends': ['base', 'report_webkit'],
    'data': [
    'report.xml',
    ],
    'installable': True,
    'application': True,
    'auto_install': False,
}
 report.py
import time
from openerp.report import report_sxw

class order(report_sxw.rml_parse):
def __init__ 
(self, cr, uid, name,context=None):
super(order, self).
__init__ (cr, uid, name, context=context)
self.localcontext.update({
'time': time,
})

report_sxw.report_sxw ('report.sale.order', 
'sale.order',
  'addons
/sale/report/ sale_order.rml',
parser=order, header="external") 
import time
from openerp.report import report_sxw

class order(report_sxw.rml_parse):
def __init__ 
(self, cr, uid, name,context=None):
super(order, self).
__init__ (cr, uid, name, context=context)
self.localcontext.update({
 'time': time,
})

report_sxw.report_sxw
('report.sale.order', 'sale.order',
'addons/sale/report/
sale_order_webkit.mako',
parser=order, header="external") 
 report.xml
<report auto="False" 
 id="report_sale_order"
 model="sale.order"
 name="sale.order"
 rml="sale/report/sale_order.rml"
 string="Quotation / Order" /> 
<report auto="False" 
 id="report_sale_order"
 model="sale.order"
 name="sale.webkit.order"
 file="webkit_sale/report/
 sale_order_webkit.mako"
 string="Quotation / Order webkit" 
 report_type="webkit" /> 

Convert RML template to the Mako template

Mako template Syntax is simpler and some extra featured then RML, like conditional statements & python code block. Mako template is having batter management for loops and expressions. RML syntax Mako syntax
 RML syntax  Mako syntax
 Expression   [[]]
eg. [[o.name or '']]
 ${}
eg. ${o.name or ''}
 Loop [[repeatIn()]]
eg. [[ repeatIn(o.order_line,'line') ]]
%for i in []: 
%endfor
eg. %for line in o.order_line: 
 %endfor
 Condition  None  %if condition:
%endif 
eg. %if i==1: %endif
 Table   <blockTable>
</blockTable>
 <table>
</table>
Paragraph
 <para>
eg. <para style="terp_default_8">
<p></p> 
eg. <p style="page-break-after:always"></p>
 Python code  None  
 python code 
%>
 Comments  <!-- comments -->  ## its a single line comment
 This 
 is multi line 
 comments 
Additional Steps: Technical Features are enabled or not.After converting it’s time to install / update the module, but before that we need to add a system parameter in OpenERP. To add System parameter go through Settings > Technical > Parameters > System Parameters, if you don’t see this menu kindly check the user configuration, if Technical Features are enabled or not. Here you need to create new system parameter, in that give key as a ‘webkit_path’ and value of wkhtmltopdf (webkit executable) which you need to download from Google Wkhtmltopdf Project. Hope this helps! Let us know for any updates over this document! Thanks.