Sample module for webkit report on purchase Order (OpenERP- 7.0)
Module Name : webkit_report_purchase_order
Requrired things to implement Webkit report
1) Download webkit to pdf library file from below link and set the system parameter.
The file is for linux and 32 bit.
Click here to Download for Linux 32 bits.
Click here to Download for Linux 64 bits.
If you have another system configuration than you can find your specific file from below link.
http://code.google.com/p/wkhtmltopdf/downloads/list
If your file is downloaded than set the path of your file inside the system parameter for that follow this menu structure
Setting >> Technical >> Parameters >> System Parameters
Create new record inside the System parameter.
Here you will ask for two fields Key and value :
Key : webkit_path
Value : set full path of your downloaded lib file (wkhtmltopdf) .
File & Directory Structure inside the module :
>>
webkit_report_purchase_order
>>
report
>>_
_init__.py
>>
purchase_webkit.py
>>
purchase_rep_webkit.mako
>>
__init__.py
>>
__openerp__.py
>>
report_view.xml
Code and Description of each files :
1)
webkit_report_purchase_order/__init__.py
* Code :
import report
*
Descriptoin :
Simply initalize the report direcotry.
2)
webkit_report_purchase_order/__openerp__.py
* Code :
{
"name": "Report Webkit 7",
"version": "1.0",
"depends": ["purchase","report_webkit"],
"author": "Serpent Consulting Services",
"category": "Purchase",
"description": """
This module is providing webkit report for purchase order
""",
'update_xml': ["report_view.xml"],
'installable': True,
'application':True,
'auto_install':False,
}
*
Descriptoin :
The openep is the Main cofig. file in module if you are not defining openerp file you will not able to see your module while you updating module list.
Inside the dependency you must give the dependancy of atleast two modules
i) report_webkit :
which is the core module for webkit report . you must give the dependency of this module.
ii) purchase:
The module name , which contain model on which you are going to generating report .
Here i have used
purchase.order model , which defined inside the purchase module. like wise on whatever model you are going to create report you must give that module name.
3)
webkit_report_purchase_order/report_view.xml
* Code :
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="purchase_rep_webk_head" model="ir.header_webkit">
<field name="footer_html"><![CDATA[
<html>
<body>
<center>Serpent Consuting Services</center>
</body>
</html>]]>
</field>
<field name="orientation">Portrait</field>
<field name="format">A4</field>
<field name="html"><![CDATA[
<html>
<body style="border:0; margin:15;" onload="subst()">
<table class="header" style="border-bottom: 0px solid black; width: 100%">
<tr>
<td style="text-align:left; font-size:15px; font-weight: bold;"><span style="text-transform:uppercase; font-size:12px;">Heading 1</td>
</tr>
<tr>
<td style="text-align:left; font-size:12px; font-weight: bold;"><span style="text-transform:uppercase; font-size:12px;">Heading 2</td>
</tr>
</table> ${_debug or ''|n} </body>
</html>]]>
</field>
<field eval="20" name="margin_top"/>
<field eval="10" name="margin_bottom"/>
<field name="css"><![CDATA[
body {
font-family:Arial;
font-size:12;
}
.cell{
border-spacing: 0;
border-collapse: collapse;
border-style:solid;
border: 1px solid grey;
font-size:10px;
text-align:center;
}
]]>
</field>
<field name="name">Purchase Webkit Header</field>
</record>
</data>
<data>
<report auto="False"
id="purchase_rep_webkit_view_id"
model="purchase.order"
name="purchase.rep.webkit"
file="report_webkit_7/report/purchase_rep_webkit.mako"
string="Purchase Extended Webkit"
report_type="webkit"
webkit_header ="purchase_rep_webk_head" />
</data>
</openerp>
* Description :
This xml file contain the xml id for the report and Header record.
Inside the header record you can define you Custom Header & Footer
Css and All the configuration of your Report Page.
4)
webkit_report_purchase_order/report/__init__.py
*
Code :
import
purchase_webkit
* Description :
This init file initalize the your parser class file.
5)
webkit_report_purchase_order/report/purchase_rep_webkit.mako
*
Code :
`<html>
<head>
<style>
${css}
</style>
</head>
<body>
%for obj in objects:
<table width="100%" border="0" class="cell_extended">
<tr class ="table_parent_data">
<td width="5%" align="center" >
<small>Description</small>
</td>
<td width="5%" align="left" class="head_bottom_border">
<small>Taxes</small>
</td>
<td width="40%" align="center" >
<small><b> Date Req.</small>
</td>
<td width="40%" align="right" >
<small><b>Qty</b></small>
</td>
<td width="5%" align="left" class="head_bottom_border">
<small>Unit Price</small>
</td>
<td width="5%" align="center">
<small>Net Price</small>
</td>
</tr>
%for line in obj.order_line:
<tr class ="table_parent_data">
<td width="5%" align="center" >
${ line.name or ''}
</td>
<td width="5%" align="left" class="head_bottom_border">
${ ', '.join(map(lambda x: x.name, line.taxes_id)) }
</td>
<td width="40%" align="center" >
${ formatLang( line.date_planned, date=True) }
</td>
<td width="40%" align="right" >
${ formatLang(line.product_qty ) line.product_uom.name }
</td>
<td width="5%" align="left" class="head_bottom_border">
${formatLang(line.price_unit, digits=get_digits(dp='Product Price') ) }
</td>
<td width="5%" align="center">
${ formatLang(line.price_subtotal, digits=get_digits(dp='Account'), currency_obj=o.pricelist_id.currency_id ) }
</td>
</tr>
%endfor
</table>
%endfor
*
Description :
I just did sample code for purchase or mako file you can customize by your own. this is the sample how you can code in mako template file.
You can easily write your python code in mako template file.
6) webkit_report_purchase_order/report/purchase_webkit.py
* Code :
from openerp.report import report_sxw
class purchase_webkit_report(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(purchase_webkit_report, self).__init__(cr, uid, name, context=context)
report_sxw.report_sxw('report.purchase.rep.webkit','purchase.order','addons/webkit_report_purchase_order/report/purchase_rep_webkit.mako',parser=purchase_webkit_report)
*
Descriptoin :
Note : This file is
not necessary but whenever you want to use your own user define method
on the report you can define inside this parser class file.
If you have any query or doubt you can ask me on comment.