Merge lp:~bruno-bottacini/report-print-send/7.0-report_webkit_custom_paper_size into lp:~report-print-send-core-editors/report-print-send/7.0

Proposed by bruno bottacini
Status: Needs review
Proposed branch: lp:~bruno-bottacini/report-print-send/7.0-report_webkit_custom_paper_size
Merge into: lp:~report-print-send-core-editors/report-print-send/7.0
Diff against target: 209 lines (+189/-0)
4 files modified
report_webkit_custom_paper_size/__init__.py (+106/-0)
report_webkit_custom_paper_size/__openerp__.py (+19/-0)
report_webkit_custom_paper_size/header.py (+47/-0)
report_webkit_custom_paper_size/header_view.xml (+17/-0)
To merge this branch: bzr merge lp:~bruno-bottacini/report-print-send/7.0-report_webkit_custom_paper_size
Reviewer Review Type Date Requested Status
Lionel Sausin - Initiatives/Numérigraphe (community) Needs Information
Yannick Vaucher @ Camptocamp moved on github Needs Resubmitting
Review via email: mp+202892@code.launchpad.net

Description of the change

add a module that permit in report_webkit to use custom paper size.
i used the GrupoCITEC patch
lp:~grupocitec/ocb-addons/report_webkit_custom_paper_size

To post a comment you must log in.
Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

I'm interested in this feature and I'm porting a custom module which hacked this feature in v6.
I'll do my best to make a review here.

Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

First off, some formal comments:
- in.txt and out.pdf should probably be left out
- README is empty, either remove it or write something in it please
- please add a copyright note at the top of your files, I think they're useful to avoid ambiguity
- in __openerp__.py:
    - please add a description
    - you may remove the fields init_xml, demo_xml, test, auto_install, complexity and installable
    - there's a space at the end of the "name" field
- it would be nice to get closer to PEP8 (no spaces before ':', 80 cols, empty lines...)
I'll examine and test the module further.

review: Needs Fixing (formal nitpicking)
Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

So this a modularization of something that is much easier to do as a patch to the core addons...
Have you been proposing your initial patch for the official addons trunk yet? If not, I humbly suggest you do (I'll review your proposal there too).

Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

Please ignore my comment about PEP8 for the copied/pasted part of the module.
However you need to update your copy of generate_pdf() because patches have been applied to it upstream.

Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) :
review: Needs Fixing (copied code is out-of-date)
Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

I've forked a branch with an updated code, and proposed to merge it into your branch: https://code.launchpad.net/~numerigraphe-team/report-print-send/7.0-report_webkit_custom_paper_size/+merge/219656

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Wouldn't it be cleaner to add a hook in report_webkit to create the command ?

review: Needs Information
Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

Yannick yes it would be much cleaner, but the problem is the same as with what was initially proposed: unfortunately it won't be accepted in stable releases.
So for v7 we can only
- either take this "white-box reuse" module
- or refuse it and ask those interested to patch their installation on their own (I for one would not mind doing that).

Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

I also noticed this proposal misses an import statement for osv_memory. Fixed it in Numérigraphe's branch.

review: Needs Fixing (missing import and out-of-date white-box reuse)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

This project is now hosted on https://github.com/OCA/report-print-send. Please move your proposal there. This guide may help you https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub

review: Needs Resubmitting (moved on github)
Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

Before someone moves this branch to github, can you please give your opinion regarding the modularity first?
This is a case of something that is done very cleanly as a path to the core, but can't ship with OCB, and is hackish as a module.
For my own deployment I decided to use the "patch" approach that I'll maintain for my own needs.
Maybe we should just encourage those interested to do the same, and insist on pushing this to odoo's master branch?

review: Needs Information

Unmerged revisions

11. By bruno bottacini

Report Webkit Custom Paper Size using the GrupoCITEC patch

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'report_webkit_custom_paper_size'
2=== added file 'report_webkit_custom_paper_size/__init__.py'
3--- report_webkit_custom_paper_size/__init__.py 1970-01-01 00:00:00 +0000
4+++ report_webkit_custom_paper_size/__init__.py 2014-01-23 16:44:31 +0000
5@@ -0,0 +1,106 @@
6+import header
7+
8+import openerp
9+import tempfile
10+import os
11+import time
12+import logging
13+import subprocess
14+from openerp.tools.translate import _
15+
16+
17+_logger = logging.getLogger(__name__)
18+
19+def generate_pdf(self, comm_path, report_xml, header, footer, html_list, webkit_header=False):
20+ """Call webkit in order to generate pdf"""
21+ if not webkit_header:
22+ webkit_header = report_xml.webkit_header
23+ tmp_dir = tempfile.gettempdir()
24+ out_filename = tempfile.mktemp(suffix=".pdf", prefix="webkit.tmp.")
25+ file_to_del = [out_filename]
26+ if comm_path:
27+ command = [comm_path]
28+ else:
29+ command = ['wkhtmltopdf']
30+
31+ command.append('--quiet')
32+ # default to UTF-8 encoding. Use <meta charset="latin-1"> to override.
33+ command.extend(['--encoding', 'utf-8'])
34+ if header :
35+ head_file = file( os.path.join(
36+ tmp_dir,
37+ str(time.time()) + '.head.html'
38+ ),
39+ 'w'
40+ )
41+ head_file.write(header)
42+ head_file.close()
43+ file_to_del.append(head_file.name)
44+ command.extend(['--header-html', head_file.name])
45+ if footer :
46+ foot_file = file( os.path.join(
47+ tmp_dir,
48+ str(time.time()) + '.foot.html'
49+ ),
50+ 'w'
51+ )
52+ foot_file.write(footer)
53+ foot_file.close()
54+ file_to_del.append(foot_file.name)
55+ command.extend(['--footer-html', foot_file.name])
56+
57+ if webkit_header.margin_top :
58+ command.extend(['--margin-top', str(webkit_header.margin_top).replace(',', '.')])
59+ if webkit_header.margin_bottom :
60+ command.extend(['--margin-bottom', str(webkit_header.margin_bottom).replace(',', '.')])
61+ if webkit_header.margin_left :
62+ command.extend(['--margin-left', str(webkit_header.margin_left).replace(',', '.')])
63+ if webkit_header.margin_right :
64+ command.extend(['--margin-right', str(webkit_header.margin_right).replace(',', '.')])
65+ if webkit_header.orientation :
66+ command.extend(['--orientation', str(webkit_header.orientation).replace(',', '.')])
67+ if webkit_header.format :
68+ if webkit_header.format=='custom':
69+ command.extend(['--page-width', str(webkit_header.paper_width).replace(',', '.')])
70+ command.extend(['--page-height', str(webkit_header.paper_height).replace(',', '.')])
71+ else:
72+ command.extend(['--page-size', str(webkit_header.format).replace(',', '.')])
73+ count = 0
74+ for html in html_list :
75+ html_file = file(os.path.join(tmp_dir, str(time.time()) + str(count) +'.body.html'), 'w')
76+ count += 1
77+ html_file.write(html)
78+ html_file.close()
79+ file_to_del.append(html_file.name)
80+ command.append(html_file.name)
81+ command.append(out_filename)
82+ stderr_fd, stderr_path = tempfile.mkstemp(text=True)
83+ file_to_del.append(stderr_path)
84+ try:
85+ status = subprocess.call(command, stderr=stderr_fd)
86+ os.close(stderr_fd) # ensure flush before reading
87+ stderr_fd = None # avoid closing again in finally block
88+ fobj = open(stderr_path, 'r')
89+ error_message = fobj.read()
90+ fobj.close()
91+ if not error_message:
92+ error_message = _('No diagnosis message was provided')
93+ else:
94+ error_message = _('The following diagnosis message was provided:\n') + error_message
95+ if status :
96+ raise except_osv(_('Webkit error' ),
97+ _("The command 'wkhtmltopdf' failed with error code = %s. Message: %s") % (status, error_message))
98+ pdf_file = open(out_filename, 'rb')
99+ pdf = pdf_file.read()
100+ pdf_file.close()
101+ finally:
102+ if stderr_fd is not None:
103+ os.close(stderr_fd)
104+ for f_to_del in file_to_del:
105+ try:
106+ os.unlink(f_to_del)
107+ except (OSError, IOError), exc:
108+ _logger.error('cannot remove file %s: %s', f_to_del, exc)
109+ return pdf
110+
111+openerp.addons.report_webkit.webkit_report.WebKitParser.generate_pdf = generate_pdf
112
113=== added file 'report_webkit_custom_paper_size/__openerp__.py'
114--- report_webkit_custom_paper_size/__openerp__.py 1970-01-01 00:00:00 +0000
115+++ report_webkit_custom_paper_size/__openerp__.py 2014-01-23 16:44:31 +0000
116@@ -0,0 +1,19 @@
117+{
118+ "name" : "Report Webkit Custom Paper Size ",
119+ "version" : "1.0",
120+ "depends" : ["report_webkit"],
121+ "author" : "Bruno Bottacini using the GrupoCITEC patch",
122+ 'complexity': "easy",
123+ "description": """
124+ """,
125+ "website" : "http://www.dorella.com",
126+ 'license': 'AGPL-3',
127+ "category" : "Reporting",
128+ "init_xml" : [],
129+ "demo_xml" : [],
130+ "data" : [ 'header_view.xml',
131+ ],
132+ "test" : [],
133+ "auto_install": False,
134+ "installable": True,
135+}
136
137=== added file 'report_webkit_custom_paper_size/header.py'
138--- report_webkit_custom_paper_size/header.py 1970-01-01 00:00:00 +0000
139+++ report_webkit_custom_paper_size/header.py 2014-01-23 16:44:31 +0000
140@@ -0,0 +1,47 @@
141+from openerp.osv import orm, fields
142+
143+class HeaderHTML(orm.Model):
144+ _inherit = "ir.header_webkit"
145+ _columns = {
146+ 'format': fields.selection(
147+ [
148+ ('A0' ,'A0 5 841 x 1189 mm'),
149+ ('A1' ,'A1 6 594 x 841 mm'),
150+ ('A2' ,'A2 7 420 x 594 mm'),
151+ ('A3' ,'A3 8 297 x 420 mm'),
152+ ('A4' ,'A4 0 210 x 297 mm, 8.26 x 11.69 inches'),
153+ ('A5' ,'A5 9 148 x 210 mm'),
154+ ('A6' ,'A6 10 105 x 148 mm'),
155+ ('A7' ,'A7 11 74 x 105 mm'),
156+ ('A8' ,'A8 12 52 x 74 mm'),
157+ ('A9' ,'A9 13 37 x 52 mm'),
158+ ('B0' ,'B0 14 1000 x 1414 mm'),
159+ ('B1' ,'B1 15 707 x 1000 mm'),
160+ ('B2' ,'B2 17 500 x 707 mm'),
161+ ('B3' ,'B3 18 353 x 500 mm'),
162+ ('B4' ,'B4 19 250 x 353 mm'),
163+ ('B5' ,'B5 1 176 x 250 mm, 6.93 x 9.84 inches'),
164+ ('B6' ,'B6 20 125 x 176 mm'),
165+ ('B7' ,'B7 21 88 x 125 mm'),
166+ ('B8' ,'B8 22 62 x 88 mm'),
167+ ('B9' ,'B9 23 33 x 62 mm'),
168+ ('B10',':B10 16 31 x 44 mm'),
169+ ('C5E','C5E 24 163 x 229 mm'),
170+ ('Comm10E','Comm10E 25 105 x 241 mm, U.S. Common 10 Envelope'),
171+ ('DLE', 'DLE 26 110 x 220 mm'),
172+ ('Executive','Executive 4 7.5 x 10 inches, 190.5 x 254 mm'),
173+ ('Folio','Folio 27 210 x 330 mm'),
174+ ('Ledger', 'Ledger 28 431.8 x 279.4 mm'),
175+ ('Legal', 'Legal 3 8.5 x 14 inches, 215.9 x 355.6 mm'),
176+ ('Letter','Letter 2 8.5 x 11 inches, 215.9 x 279.4 mm'),
177+ ('Tabloid', 'Tabloid 29 279.4 x 431.8 mm'),
178+ ('custom', 'Custom Paper Size'),
179+ ],
180+ 'Paper size',
181+ required=True,
182+ help="Select Proper Paper size"
183+ ),
184+ 'paper_width': fields.integer('Paper Width (mm)'),
185+ 'paper_height': fields.integer('Paper Height (mm)'),
186+ }
187+
188
189=== added file 'report_webkit_custom_paper_size/header_view.xml'
190--- report_webkit_custom_paper_size/header_view.xml 1970-01-01 00:00:00 +0000
191+++ report_webkit_custom_paper_size/header_view.xml 2014-01-23 16:44:31 +0000
192@@ -0,0 +1,17 @@
193+<openerp>
194+ <data>
195+
196+ <record model="ir.ui.view" id="header_webkit_custom_paper_size">
197+ <field name="name">res.company.header.html.custom.paper.size</field>
198+ <field name="model">ir.header_webkit</field>
199+ <field name="inherit_id" ref="report_webkit.header_webkit"/>
200+ <field name="arch" type="xml">
201+ <field name="format" position="after">
202+ <field name="paper_width" attrs="{'invisible': [('format', '!=', 'custom')], 'required': [('format', '=', 'custom')]}" />
203+ <field name="paper_height" attrs="{'invisible': [('format', '!=', 'custom')], 'required': [('format', '=', 'custom')]}" />
204+ </field>
205+ </field>
206+ </record>
207+
208+ </data>
209+</openerp>