diff options
| author | Rucha (Open ERP) <rpa@tinyerp.com> | 2011-11-02 10:58:27 +0530 |
|---|---|---|
| committer | Rucha (Open ERP) <rpa@tinyerp.com> | 2011-11-02 10:58:27 +0530 |
| commit | 2fdecf4717080ea98a514b67dedefc27d76c6727 (patch) | |
| tree | bb54dd0e81af0bbf999fee1110fecb9e507f51e1 /addons/report_webkit | |
| parent | 9fe0f6fa83b84d0806359bdc2a3ae31dfb7e997a (diff) | |
| parent | 3d22bb8b55d48e5ee8226f023555f003288b157a (diff) | |
[MERGE]: Merge with latest trunk
bzr revid: rpa@tinyerp.com-20111102052827-0bctjrhb4amyg6pl
Diffstat (limited to 'addons/report_webkit')
23 files changed, 209 insertions, 223 deletions
diff --git a/addons/report_webkit/__openerp__.py b/addons/report_webkit/__openerp__.py index 339818a646b..52f03efaff7 100644 --- a/addons/report_webkit/__openerp__.py +++ b/addons/report_webkit/__openerp__.py @@ -38,43 +38,53 @@ This module adds a new Report Engine based on WebKit library (wkhtmltopdf) to su The module structure and some code is inspired by the report_openoffice module. The module allows: - -HTML report definition - -Multi header support - -Multi logo - -Multi company support - -HTML and CSS-3 support (In the limit of the actual WebKIT version) - -JavaScript support - -Raw HTML debugger - -Book printing capabilities - -Margins definition - -Paper size definition + + - HTML report definition + - Multi header support + - Multi logo + - Multi company support + - HTML and CSS-3 support (In the limit of the actual WebKIT version) + - JavaScript support + - Raw HTML debugger + - Book printing capabilities + - Margins definition + - Paper size definition ... and much more Multiple headers and logos can be defined per company. -CSS style, header and footer body are defined per company - -The library to install can be found here -http://code.google.com/p/wkhtmltopdf/ -The system libraries are available for Linux, Mac OS X i386 and Windows 32. - -After installing the wkhtmltopdf library on the OpenERP Server machine, you need to set the -path to the wkthtmltopdf executable file on the Company. +CSS style, header and footer body are defined per company. For a sample report see also the webkit_report_sample module, and this video: http://files.me.com/nbessi/06n92k.mov +Requirements and Installation +----------------------------- +This module requires the ``wkthtmltopdf`` library to render HTML documents as +PDF. Version 0.9.9 or later is necessary, and can be found at http://code.google.com/p/wkhtmltopdf/ +for Linux, Mac OS X (i386) and Windows (32bits). + +After installing the library on the OpenERP Server machine, you need to set the +path to the ``wkthtmltopdf`` executable file on each Company. + +If you are experiencing missing header/footer problems on Linux, be sure to +install a "static" version of the library. The default ``wkhtmltopdf`` on +Ubuntu is known to have this issue. + + +TODO +---- + + * JavaScript support activation deactivation + * Collated and book format support + * Zip return for separated PDF + * Web client WYSIWYG -TODO : -JavaScript support activation deactivation -Collated and book format support -Zip return for separated PDF -Web client WYSIWYG """, "version" : "0.9", "depends" : ["base"], - "author" : "Camptocamp SA - NBessi", - "category": "Hidden", + "author" : "Camptocamp", + "category": "Hidden", # i.e a technical module, not shown in Application install menu "url": "http://http://www.camptocamp.com/", "data": [ "security/ir.model.access.csv", "data.xml", diff --git a/addons/report_webkit/company.py b/addons/report_webkit/company.py index 82e9f406567..5b826617417 100644 --- a/addons/report_webkit/company.py +++ b/addons/report_webkit/company.py @@ -33,24 +33,28 @@ from osv import fields, osv class ResCompany(osv.osv): """Override company to add Header object link a company can have many header and logos""" - + _inherit = "res.company" _columns = { 'header_image' : fields.many2many( - 'ir.header_img', - 'company_img_rel', - 'company_id', - 'img_id', + 'ir.header_img', + 'company_img_rel', + 'company_id', + 'img_id', 'Available Images', ), 'header_webkit' : fields.many2many( - 'ir.header_webkit', - 'company_html_rel', - 'company_id', - 'html_id', + 'ir.header_webkit', + 'company_html_rel', + 'company_id', + 'html_id', 'Available html', ), - 'lib_path' : fields.char('Webkit Executable Path', size=264, help="Complete (Absolute) path to the wkhtmltopdf executable."), + 'lib_path' : fields.char('Webkit Executable Path', size=264, + help="Full path to the wkhtmltopdf executable file. " + "Version 0.9.9 is required. Install a static version " + "of the library if you experience missing header/footers " + "on Linux."), - } -ResCompany()
\ No newline at end of file + } +ResCompany() diff --git a/addons/report_webkit/default_header.html b/addons/report_webkit/default_header.html new file mode 100644 index 00000000000..0798209a5b7 --- /dev/null +++ b/addons/report_webkit/default_header.html @@ -0,0 +1,22 @@ +<html> + <head> + <meta content="text/html; charset=UTF-8" http-equiv="content-type"/> + <style type="text/css"> + ${css} + </style> + <script> + function subst() { + var vars={}; + var x=document.location.search.substring(1).split('&'); + for(var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);} + var x=['frompage','topage','page','webpage','section','subsection','subsubsection']; + for(var i in x) { + var y = document.getElementsByClassName(x[i]); + for(var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]]; + } + } + </script> + </head> +<body style="border:0; margin: 0;" onload="subst()"> +</body> +</html>
\ No newline at end of file diff --git a/addons/report_webkit/header.py b/addons/report_webkit/header.py index b8ff6fb2956..53252c5e245 100644 --- a/addons/report_webkit/header.py +++ b/addons/report_webkit/header.py @@ -33,7 +33,7 @@ from osv import fields, osv class HeaderHTML(osv.osv): """HTML Header allows you to define HTML CSS and Page format""" - + _name = "ir.header_webkit" _columns = { 'company_id' : fields.many2one('res.company', 'Company'), @@ -86,7 +86,7 @@ class HeaderHTML(osv.osv): required=True, help="Select Proper Paper size" ) - } + } HeaderHTML() class HeaderImage(osv.osv): @@ -97,5 +97,5 @@ class HeaderImage(osv.osv): 'img' : fields.binary('Image'), 'name' : fields.char('Name', size=128, required =True, help="Name of Image"), 'type' : fields.char('Type', size=32, required =True, help="Image type(png,gif,jpeg)") - } -HeaderImage()
\ No newline at end of file + } +HeaderImage() diff --git a/addons/report_webkit/header_view.xml b/addons/report_webkit/header_view.xml index d3e9363acd7..267bc7cb0a4 100644 --- a/addons/report_webkit/header_view.xml +++ b/addons/report_webkit/header_view.xml @@ -6,31 +6,26 @@ <field name="type">form</field> <field name="arch" type="xml"> <form> - <field name='company_id' /> - <newline /> - <field name="name"/> - <field name="type"/> + <group col="6" colspan="4"> + <field name="name"/> + <field name="type"/> + <field name='company_id' /> + </group> <field name="img" widget="image" colspan="4"/> </form> </field> </record> - + <record model="ir.ui.view" id="header_webkit"> <field name="name">res.company.header.html</field> <field name="model">ir.header_webkit</field> <field name="type">form</field> <field name="arch" type="xml"> <form> - <field name="name"/> - <newline/> - <notebook> - <page string="Content and styling" > - <field name='company_id' /> - <field name="css" colspan="4"/> - <field name="html" colspan="4"/> - <field name="footer_html" colspan="4" /> - </page> - <page string="page setup" > + <field name="name" colspan="4"/> + <notebook colspan="4"> + <page string="Company and Page Setup" > + <field name='company_id' colspan="4"/> <field name="orientation" /> <field name="format" /> <field name="margin_top" /> @@ -38,27 +33,35 @@ <field name="margin_left" /> <field name="margin_right" /> </page> + <page string="CSS Style" > + <field name="css" colspan="4" nolabel="1"/> + </page> + <page string="Header" > + <field name="html" colspan="4" nolabel="1"/> + </page> + <page string="Footer" > + <field name="footer_html" colspan="4" nolabel="1"/> + </page> </notebook> </form> </field> </record> - + <record id="action_header_img" model="ir.actions.act_window"> - <field name="name">Header IMG</field> + <field name="name">Webkit Logos</field> <field name="res_model">ir.header_img</field> <field name="view_type">form</field> <field name="view_mode">tree,form</field> </record> <menuitem action="action_header_img" id="menu_header_img" parent="base.menu_res_company_global" sequence="14"/> - + <record id="action_header_webkit" model="ir.actions.act_window"> - <field name="name">Header HTML</field> + <field name="name">Webkit Headers/Footers</field> <field name="res_model">ir.header_webkit</field> <field name="view_type">form</field> <field name="view_mode">tree,form</field> </record> <menuitem action="action_header_webkit" id="menu_header_webkit" parent="base.menu_res_company_global" sequence="14"/> - - + </data> </openerp> diff --git a/addons/report_webkit/i18n/bg.po b/addons/report_webkit/i18n/bg.po index bb97f618316..2b7078ed053 100644 --- a/addons/report_webkit/i18n/bg.po +++ b/addons/report_webkit/i18n/bg.po @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2011-09-05 05:57+0000\n" -"X-Generator: Launchpad (build 13830)\n" +"X-Launchpad-Export-Date: 2011-10-19 05:51+0000\n" +"X-Generator: Launchpad (build 14157)\n" #. module: report_webkit #: field:ir.actions.report.xml,webkit_header:0 diff --git a/addons/report_webkit/i18n/ca.po b/addons/report_webkit/i18n/ca.po index cf1f84244db..f032acdab66 100644 --- a/addons/report_webkit/i18n/ca.po +++ b/addons/report_webkit/i18n/ca.po @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2011-09-05 05:57+0000\n" -"X-Generator: Launchpad (build 13830)\n" +"X-Launchpad-Export-Date: 2011-10-19 05:51+0000\n" +"X-Generator: Launchpad (build 14157)\n" #. module: report_webkit #: field:ir.actions.report.xml,webkit_header:0 diff --git a/addons/report_webkit/i18n/de.po b/addons/report_webkit/i18n/de.po index bd810e5f4d9..1a7760d4795 100644 --- a/addons/report_webkit/i18n/de.po +++ b/addons/report_webkit/i18n/de.po @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2011-09-05 05:57+0000\n" -"X-Generator: Launchpad (build 13830)\n" +"X-Launchpad-Export-Date: 2011-10-19 05:51+0000\n" +"X-Generator: Launchpad (build 14157)\n" #. module: report_webkit #: field:ir.actions.report.xml,webkit_header:0 diff --git a/addons/report_webkit/i18n/es.po b/addons/report_webkit/i18n/es.po index 8e0b1ac5a2a..d7e67093af0 100644 --- a/addons/report_webkit/i18n/es.po +++ b/addons/report_webkit/i18n/es.po @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2011-09-05 05:57+0000\n" -"X-Generator: Launchpad (build 13830)\n" +"X-Launchpad-Export-Date: 2011-10-19 05:51+0000\n" +"X-Generator: Launchpad (build 14157)\n" #. module: report_webkit #: field:ir.actions.report.xml,webkit_header:0 diff --git a/addons/report_webkit/i18n/fi.po b/addons/report_webkit/i18n/fi.po index df6441609b0..d65476339fd 100644 --- a/addons/report_webkit/i18n/fi.po +++ b/addons/report_webkit/i18n/fi.po @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2011-09-05 05:57+0000\n" -"X-Generator: Launchpad (build 13830)\n" +"X-Launchpad-Export-Date: 2011-10-19 05:51+0000\n" +"X-Generator: Launchpad (build 14157)\n" #. module: report_webkit #: field:ir.actions.report.xml,webkit_header:0 diff --git a/addons/report_webkit/i18n/fr.po b/addons/report_webkit/i18n/fr.po index 40031bec54a..4eacf39f3ff 100644 --- a/addons/report_webkit/i18n/fr.po +++ b/addons/report_webkit/i18n/fr.po @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2011-09-05 05:57+0000\n" -"X-Generator: Launchpad (build 13830)\n" +"X-Launchpad-Export-Date: 2011-10-19 05:51+0000\n" +"X-Generator: Launchpad (build 14157)\n" #. module: report_webkit #: field:ir.actions.report.xml,webkit_header:0 diff --git a/addons/report_webkit/i18n/hu.po b/addons/report_webkit/i18n/hu.po index 537a4616687..38578651337 100644 --- a/addons/report_webkit/i18n/hu.po +++ b/addons/report_webkit/i18n/hu.po @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2011-09-05 05:57+0000\n" -"X-Generator: Launchpad (build 13830)\n" +"X-Launchpad-Export-Date: 2011-10-19 05:51+0000\n" +"X-Generator: Launchpad (build 14157)\n" #. module: report_webkit #: field:ir.actions.report.xml,webkit_header:0 diff --git a/addons/report_webkit/i18n/it.po b/addons/report_webkit/i18n/it.po index 91f0b73c6ed..95806efd30f 100644 --- a/addons/report_webkit/i18n/it.po +++ b/addons/report_webkit/i18n/it.po @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2011-09-05 05:57+0000\n" -"X-Generator: Launchpad (build 13830)\n" +"X-Launchpad-Export-Date: 2011-10-19 05:51+0000\n" +"X-Generator: Launchpad (build 14157)\n" #. module: report_webkit #: field:ir.actions.report.xml,webkit_header:0 diff --git a/addons/report_webkit/i18n/nl.po b/addons/report_webkit/i18n/nl.po index 2ba1c892946..63ebd12b195 100644 --- a/addons/report_webkit/i18n/nl.po +++ b/addons/report_webkit/i18n/nl.po @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2011-09-05 05:57+0000\n" -"X-Generator: Launchpad (build 13830)\n" +"X-Launchpad-Export-Date: 2011-10-19 05:51+0000\n" +"X-Generator: Launchpad (build 14157)\n" #. module: report_webkit #: field:ir.actions.report.xml,webkit_header:0 diff --git a/addons/report_webkit/i18n/pl.po b/addons/report_webkit/i18n/pl.po index 6044b36a7a7..be7fc41db87 100644 --- a/addons/report_webkit/i18n/pl.po +++ b/addons/report_webkit/i18n/pl.po @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2011-09-05 05:57+0000\n" -"X-Generator: Launchpad (build 13830)\n" +"X-Launchpad-Export-Date: 2011-10-19 05:51+0000\n" +"X-Generator: Launchpad (build 14157)\n" #. module: report_webkit #: field:ir.actions.report.xml,webkit_header:0 diff --git a/addons/report_webkit/i18n/pt.po b/addons/report_webkit/i18n/pt.po index 6e93f884bec..563a45a1bdd 100644 --- a/addons/report_webkit/i18n/pt.po +++ b/addons/report_webkit/i18n/pt.po @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2011-09-05 05:57+0000\n" -"X-Generator: Launchpad (build 13830)\n" +"X-Launchpad-Export-Date: 2011-10-19 05:51+0000\n" +"X-Generator: Launchpad (build 14157)\n" #. module: report_webkit #: field:ir.actions.report.xml,webkit_header:0 diff --git a/addons/report_webkit/i18n/pt_BR.po b/addons/report_webkit/i18n/pt_BR.po index 60a397ac82d..6b158330b06 100644 --- a/addons/report_webkit/i18n/pt_BR.po +++ b/addons/report_webkit/i18n/pt_BR.po @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2011-09-05 05:57+0000\n" -"X-Generator: Launchpad (build 13830)\n" +"X-Launchpad-Export-Date: 2011-10-19 05:51+0000\n" +"X-Generator: Launchpad (build 14157)\n" #. module: report_webkit #: field:ir.actions.report.xml,webkit_header:0 diff --git a/addons/report_webkit/i18n/ru.po b/addons/report_webkit/i18n/ru.po index 64d680e6d41..8217cf01622 100644 --- a/addons/report_webkit/i18n/ru.po +++ b/addons/report_webkit/i18n/ru.po @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2011-09-05 05:57+0000\n" -"X-Generator: Launchpad (build 13830)\n" +"X-Launchpad-Export-Date: 2011-10-19 05:51+0000\n" +"X-Generator: Launchpad (build 14157)\n" #. module: report_webkit #: field:ir.actions.report.xml,webkit_header:0 diff --git a/addons/report_webkit/i18n/zh_CN.po b/addons/report_webkit/i18n/zh_CN.po index aebf1e6536e..954662f6073 100644 --- a/addons/report_webkit/i18n/zh_CN.po +++ b/addons/report_webkit/i18n/zh_CN.po @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2011-09-05 05:57+0000\n" -"X-Generator: Launchpad (build 13830)\n" +"X-Launchpad-Export-Date: 2011-10-19 05:51+0000\n" +"X-Generator: Launchpad (build 14157)\n" #. module: report_webkit #: field:ir.actions.report.xml,webkit_header:0 diff --git a/addons/report_webkit/ir_report.py b/addons/report_webkit/ir_report.py index e6f4a81f9e7..bca10b0d1d8 100644 --- a/addons/report_webkit/ir_report.py +++ b/addons/report_webkit/ir_report.py @@ -123,13 +123,16 @@ class ReportXML(osv.osv): 'ir.header_webkit', type='many2one', relation='ir.header_webkit', - string='WebKit Header', + string='Webkit Header', help="The header linked to the report", view_load=True, required=True ), 'webkit_debug' : fields.boolean('Webkit debug', help="Enable the webkit engine debugger"), 'report_webkit_data': fields.text('Webkit Template', help="This template will be used if the main report file is not found"), + 'precise_mode':fields.boolean('Precise Mode', help='This mode allow more precise element \ + position as each object is printed on a separate HTML.\ + but memory and disk usage is wider') } ReportXML() diff --git a/addons/report_webkit/ir_report_view.xml b/addons/report_webkit/ir_report_view.xml index e92c5a5345b..1d60f6a873d 100644 --- a/addons/report_webkit/ir_report_view.xml +++ b/addons/report_webkit/ir_report_view.xml @@ -10,6 +10,7 @@ <page string="Webkit" attrs="{'invisible':[('report_type','!=','webkit')]}"> <field name="webkit_header"/> <field name="webkit_debug"/> + <field name="precise_mode"/> <separator string="Webkit Template (used if Report File is not found)" colspan="4"/> <field name="report_webkit_data" colspan="4" nolabel="1"/> </page> diff --git a/addons/report_webkit/security/ir.model.access.csv b/addons/report_webkit/security/ir.model.access.csv index 440bd5e4a3e..6c626f9873e 100644 --- a/addons/report_webkit/security/ir.model.access.csv +++ b/addons/report_webkit/security/ir.model.access.csv @@ -1,3 +1,3 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" "access_ir_header_webkit","ir.header_webkit","model_ir_header_webkit",,1,,1, -"access_ir_header_img","ir.header_img","model_ir_header_img",,1,,1, +"access_ir_header_img","ir.header_img","model_ir_header_img",,1,,1,
\ No newline at end of file diff --git a/addons/report_webkit/webkit_report.py b/addons/report_webkit/webkit_report.py index 406013cef12..8d6373e412b 100644 --- a/addons/report_webkit/webkit_report.py +++ b/addons/report_webkit/webkit_report.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################## # -# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com) +# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com) # All Right Reserved # # Author : Nicolas Bessi (Camptocamp) @@ -35,8 +35,11 @@ import os import report import tempfile import time +import logging + from mako.template import Template from mako import exceptions + import netsvc import pooler from report_helper import WebKitHelper @@ -46,6 +49,7 @@ import tools from tools.translate import _ from osv.osv import except_osv +logger = logging.getLogger('report_webkit') def mako_template(text): """Build a Mako template. @@ -60,12 +64,12 @@ class WebKitParser(report_sxw): """Custom class that use webkit to render HTML reports Code partially taken from report openoffice. Thanks guys :) """ - - def __init__(self, name, table, rml=False, parser=False, + + def __init__(self, name, table, rml=False, parser=False, header=True, store=False): self.parser_instance = False self.localcontext={} - report_sxw.__init__(self, name, table, rml, parser, + report_sxw.__init__(self, name, table, rml, parser, header, store) def get_lib(self, cursor, uid, company) : @@ -81,7 +85,7 @@ class WebKitParser(report_sxw): ' http://code.google.com/p/wkhtmltopdf/downloads/list and set the'+ ' path to the executable on the Company form.'+ 'Minimal version is 0.9.9') - ) + ) if os.path.isabs(path) : if (os.path.exists(path) and os.access(path, os.X_OK)\ and os.path.basename(path).startswith('wkhtmltopdf')): @@ -118,7 +122,7 @@ class WebKitParser(report_sxw): head_file = file( os.path.join( tmp_dir, str(time.time()) + '.head.html' - ), + ), 'w' ) head_file.write(header) @@ -129,14 +133,14 @@ class WebKitParser(report_sxw): foot_file = file( os.path.join( tmp_dir, str(time.time()) + '.foot.html' - ), + ), 'w' ) foot_file.write(footer) foot_file.close() file_to_del.append(foot_file.name) command.extend(['--footer-html', foot_file.name]) - + if webkit_header.margin_top : command.extend(['--margin-top', str(webkit_header.margin_top).replace(',', '.')]) if webkit_header.margin_bottom : @@ -163,7 +167,7 @@ class WebKitParser(report_sxw): status = subprocess.call(command, stderr=subprocess.PIPE) # ignore stderr if status : raise except_osv( - _('Webkit raise an error' ), + _('Webkit raise an error' ), status ) except Exception: @@ -176,68 +180,30 @@ class WebKitParser(report_sxw): os.unlink(out) return pdf - - - def setLang(self, lang): - if not lang: - lang = 'en_US' - self.localcontext['lang'] = lang def translate_call(self, src): """Translate String.""" ir_translation = self.pool.get('ir.translation') - res = ir_translation._get_source(self.parser_instance.cr, self.parser_instance.uid, self.name, 'report', self.localcontext.get('lang', 'en_US'), src) + res = ir_translation._get_source(self.parser_instance.cr, self.parser_instance.uid, + self.name, 'report', self.parser_instance.localcontext.get('lang', 'en_US'), src) if not res : return src - return res - - def formatLang(self, value, digits=None, date=False, date_time=False, grouping=True, monetary=False): - """format using the know cursor, language from localcontext""" - if digits is None: - digits = self.parser_instance.get_digits(value) - if isinstance(value, (str, unicode)) and not value: - return '' - pool_lang = self.pool.get('res.lang') - lang = self.localcontext['lang'] - - lang_ids = pool_lang.search(self.parser_instance.cr, self.parser_instance.uid, [('code','=',lang)])[0] - lang_obj = pool_lang.browse(self.parser_instance.cr, self.parser_instance.uid, lang_ids) - - if date or date_time: - if not str(value): - return '' - - date_format = lang_obj.date_format - parse_format = '%Y-%m-%d' - if date_time: - value=value.split('.')[0] - date_format = date_format + " " + lang_obj.time_format - parse_format = '%Y-%m-%d %H:%M:%S' - if not isinstance(value, time.struct_time): - return time.strftime(date_format, time.strptime(value, parse_format)) + return res - else: - date = datetime(*value.timetuple()[:6]) - return date.strftime(date_format) - - return lang_obj.format('%.' + str(digits) + 'f', value, grouping=grouping, monetary=monetary) - - # override needed to keep the attachments' storing procedure + # override needed to keep the attachments storing procedure def create_single_pdf(self, cursor, uid, ids, data, report_xml, context=None): """generate the PDF""" - + if context is None: context={} - + htmls = [] if report_xml.report_type != 'webkit': return super(WebKitParser,self).create_single_pdf(cursor, uid, ids, data, report_xml, context=context) - self.parser_instance = self.parser( - cursor, - uid, - self.name2, - context=context - ) + self.parser_instance = self.parser(cursor, + uid, + self.name2, + context=context) self.pool = pooler.get_pool(cursor.dbname) objs = self.getObjects(cursor, uid, ids, context) @@ -256,66 +222,55 @@ class WebKitParser(report_sxw): header = report_xml.webkit_header.html footer = report_xml.webkit_header.footer_html if not header and report_xml.header: - raise except_osv( - _('No header defined for this Webkit report!'), - _('Please set a header in company settings') - ) + raise except_osv( + _('No header defined for this Webkit report!'), + _('Please set a header in company settings') + ) if not report_xml.header : - #I know it could be cleaner ... - header = u""" -<html> - <head> - <meta content="text/html; charset=UTF-8" http-equiv="content-type"/> - <style type="text/css"> - ${css} - </style> - <script> - function subst() { - var vars={}; - var x=document.location.search.substring(1).split('&'); - for(var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);} - var x=['frompage','topage','page','webpage','section','subsection','subsubsection']; - for(var i in x) { - var y = document.getElementsByClassName(x[i]); - for(var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]]; - } - } - </script> - </head> -<body style="border:0; margin: 0;" onload="subst()"> -</body> -</html>""" + header = '' + default_head = addons.get_module_resource('report_webkit', 'default_header.html') + with open(default_head,'r') as f: + header = f.read() css = report_xml.webkit_header.css if not css : css = '' user = self.pool.get('res.users').browse(cursor, uid, uid) company= user.company_id - + #default_filters=['unicode', 'entity'] can be used to set global filter body_mako_tpl = mako_template(template) helper = WebKitHelper(cursor, uid, report_xml.id, context) - try : - html = body_mako_tpl.render( helper=helper, - css=css, - _=self.translate_call, - **self.parser_instance.localcontext - ) - except Exception, e: - msg = exceptions.text_error_template().render() - netsvc.Logger().notifyChannel('Webkit render', netsvc.LOG_ERROR, msg) - raise except_osv(_('Webkit render'), msg) + if report_xml.precise_mode: + for obj in objs: + self.parser_instance.localcontext['objects'] = [obj] + try : + html = body_mako_tpl.render(helper=helper, + css=css, + _=self.translate_call, + **self.parser_instance.localcontext) + htmls.append(html) + except Exception, e: + msg = exceptions.text_error_template().render() + logger.error(msg) + raise except_osv(_('Webkit render'), msg) + else: + try : + html = body_mako_tpl.render(helper=helper, + css=css, + _=self.translate_call, + **self.parser_instance.localcontext) + htmls.append(html) + except Exception, e: + msg = exceptions.text_error_template().render() + logger.error(msg) + raise except_osv(_('Webkit render'), msg) head_mako_tpl = mako_template(header) try : - head = head_mako_tpl.render( - company=company, - time=time, - helper=helper, + head = head_mako_tpl.render(helper=helper, css=css, - formatLang=self.formatLang, - setLang=self.setLang, _=self.translate_call, - _debug=False - ) + _debug=False, + **self.parser_instance.localcontext) except Exception, e: raise except_osv(_('Webkit render'), exceptions.text_error_template().render()) @@ -323,38 +278,28 @@ class WebKitParser(report_sxw): if footer : foot_mako_tpl = mako_template(footer) try : - foot = foot_mako_tpl.render( - company=company, - time=time, - helper=helper, + foot = foot_mako_tpl.render(helper=helper, css=css, - formatLang=self.formatLang, - setLang=self.setLang, _=self.translate_call, - ) + **self.parser_instance.localcontext) except: msg = exceptions.text_error_template().render() - netsvc.Logger().notifyChannel('Webkit render', netsvc.LOG_ERROR, msg) + logger.error(msg) raise except_osv(_('Webkit render'), msg) if report_xml.webkit_debug : try : - deb = head_mako_tpl.render( - company=company, - time=time, - helper=helper, - css=css, - _debug=tools.ustr(html), - formatLang=self.formatLang, - setLang=self.setLang, - _=self.translate_call, - ) + deb = head_mako_tpl.render(helper=helper, + css=css, + _debug=tools.ustr("\n".join(htmls)), + _=self.translate_call, + **self.parser_instance.localcontext) except Exception, e: msg = exceptions.text_error_template().render() - netsvc.Logger().notifyChannel('Webkit render', netsvc.LOG_ERROR, msg) + logger.error(msg) raise except_osv(_('Webkit render'), msg) return (deb, 'html') bin = self.get_lib(cursor, uid, company.id) - pdf = self.generate_pdf(bin, report_xml, head, foot, [html]) + pdf = self.generate_pdf(bin, report_xml, head, foot, htmls) return (pdf, 'pdf') @@ -366,13 +311,11 @@ class WebKitParser(report_sxw): report_xml_ids = ir_obj.search(cursor, uid, [('report_name', '=', self.name[7:])], context=context) if report_xml_ids: - - report_xml = ir_obj.browse( - cursor, - uid, - report_xml_ids[0], - context=context - ) + + report_xml = ir_obj.browse(cursor, + uid, + report_xml_ids[0], + context=context) report_xml.report_rml = None report_xml.report_rml_content = None report_xml.report_sxw_content_data = None |
