Guide to convert RML Report to Webkit Report

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

 

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 report.

  • 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

 

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 .

 

 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

 

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" /> 

 

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

 

<%doc> 
 This 
 is multi line 
 comments 
<%/doc>

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.

 

from: http://www.serpentcs.com/serpentcs-rml-to-webkit-report-guide

 

你可能感兴趣的:(convert)