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
=== added directory 'report_webkit_custom_paper_size'
=== added file 'report_webkit_custom_paper_size/__init__.py'
--- report_webkit_custom_paper_size/__init__.py 1970-01-01 00:00:00 +0000
+++ report_webkit_custom_paper_size/__init__.py 2014-01-23 16:44:31 +0000
@@ -0,0 +1,106 @@
1import header
2
3import openerp
4import tempfile
5import os
6import time
7import logging
8import subprocess
9from openerp.tools.translate import _
10
11
12_logger = logging.getLogger(__name__)
13
14def generate_pdf(self, comm_path, report_xml, header, footer, html_list, webkit_header=False):
15 """Call webkit in order to generate pdf"""
16 if not webkit_header:
17 webkit_header = report_xml.webkit_header
18 tmp_dir = tempfile.gettempdir()
19 out_filename = tempfile.mktemp(suffix=".pdf", prefix="webkit.tmp.")
20 file_to_del = [out_filename]
21 if comm_path:
22 command = [comm_path]
23 else:
24 command = ['wkhtmltopdf']
25
26 command.append('--quiet')
27 # default to UTF-8 encoding. Use <meta charset="latin-1"> to override.
28 command.extend(['--encoding', 'utf-8'])
29 if header :
30 head_file = file( os.path.join(
31 tmp_dir,
32 str(time.time()) + '.head.html'
33 ),
34 'w'
35 )
36 head_file.write(header)
37 head_file.close()
38 file_to_del.append(head_file.name)
39 command.extend(['--header-html', head_file.name])
40 if footer :
41 foot_file = file( os.path.join(
42 tmp_dir,
43 str(time.time()) + '.foot.html'
44 ),
45 'w'
46 )
47 foot_file.write(footer)
48 foot_file.close()
49 file_to_del.append(foot_file.name)
50 command.extend(['--footer-html', foot_file.name])
51
52 if webkit_header.margin_top :
53 command.extend(['--margin-top', str(webkit_header.margin_top).replace(',', '.')])
54 if webkit_header.margin_bottom :
55 command.extend(['--margin-bottom', str(webkit_header.margin_bottom).replace(',', '.')])
56 if webkit_header.margin_left :
57 command.extend(['--margin-left', str(webkit_header.margin_left).replace(',', '.')])
58 if webkit_header.margin_right :
59 command.extend(['--margin-right', str(webkit_header.margin_right).replace(',', '.')])
60 if webkit_header.orientation :
61 command.extend(['--orientation', str(webkit_header.orientation).replace(',', '.')])
62 if webkit_header.format :
63 if webkit_header.format=='custom':
64 command.extend(['--page-width', str(webkit_header.paper_width).replace(',', '.')])
65 command.extend(['--page-height', str(webkit_header.paper_height).replace(',', '.')])
66 else:
67 command.extend(['--page-size', str(webkit_header.format).replace(',', '.')])
68 count = 0
69 for html in html_list :
70 html_file = file(os.path.join(tmp_dir, str(time.time()) + str(count) +'.body.html'), 'w')
71 count += 1
72 html_file.write(html)
73 html_file.close()
74 file_to_del.append(html_file.name)
75 command.append(html_file.name)
76 command.append(out_filename)
77 stderr_fd, stderr_path = tempfile.mkstemp(text=True)
78 file_to_del.append(stderr_path)
79 try:
80 status = subprocess.call(command, stderr=stderr_fd)
81 os.close(stderr_fd) # ensure flush before reading
82 stderr_fd = None # avoid closing again in finally block
83 fobj = open(stderr_path, 'r')
84 error_message = fobj.read()
85 fobj.close()
86 if not error_message:
87 error_message = _('No diagnosis message was provided')
88 else:
89 error_message = _('The following diagnosis message was provided:\n') + error_message
90 if status :
91 raise except_osv(_('Webkit error' ),
92 _("The command 'wkhtmltopdf' failed with error code = %s. Message: %s") % (status, error_message))
93 pdf_file = open(out_filename, 'rb')
94 pdf = pdf_file.read()
95 pdf_file.close()
96 finally:
97 if stderr_fd is not None:
98 os.close(stderr_fd)
99 for f_to_del in file_to_del:
100 try:
101 os.unlink(f_to_del)
102 except (OSError, IOError), exc:
103 _logger.error('cannot remove file %s: %s', f_to_del, exc)
104 return pdf
105
106openerp.addons.report_webkit.webkit_report.WebKitParser.generate_pdf = generate_pdf
0107
=== added file 'report_webkit_custom_paper_size/__openerp__.py'
--- report_webkit_custom_paper_size/__openerp__.py 1970-01-01 00:00:00 +0000
+++ report_webkit_custom_paper_size/__openerp__.py 2014-01-23 16:44:31 +0000
@@ -0,0 +1,19 @@
1{
2 "name" : "Report Webkit Custom Paper Size ",
3 "version" : "1.0",
4 "depends" : ["report_webkit"],
5 "author" : "Bruno Bottacini using the GrupoCITEC patch",
6 'complexity': "easy",
7 "description": """
8 """,
9 "website" : "http://www.dorella.com",
10 'license': 'AGPL-3',
11 "category" : "Reporting",
12 "init_xml" : [],
13 "demo_xml" : [],
14 "data" : [ 'header_view.xml',
15 ],
16 "test" : [],
17 "auto_install": False,
18 "installable": True,
19}
020
=== added file 'report_webkit_custom_paper_size/header.py'
--- report_webkit_custom_paper_size/header.py 1970-01-01 00:00:00 +0000
+++ report_webkit_custom_paper_size/header.py 2014-01-23 16:44:31 +0000
@@ -0,0 +1,47 @@
1from openerp.osv import orm, fields
2
3class HeaderHTML(orm.Model):
4 _inherit = "ir.header_webkit"
5 _columns = {
6 'format': fields.selection(
7 [
8 ('A0' ,'A0 5 841 x 1189 mm'),
9 ('A1' ,'A1 6 594 x 841 mm'),
10 ('A2' ,'A2 7 420 x 594 mm'),
11 ('A3' ,'A3 8 297 x 420 mm'),
12 ('A4' ,'A4 0 210 x 297 mm, 8.26 x 11.69 inches'),
13 ('A5' ,'A5 9 148 x 210 mm'),
14 ('A6' ,'A6 10 105 x 148 mm'),
15 ('A7' ,'A7 11 74 x 105 mm'),
16 ('A8' ,'A8 12 52 x 74 mm'),
17 ('A9' ,'A9 13 37 x 52 mm'),
18 ('B0' ,'B0 14 1000 x 1414 mm'),
19 ('B1' ,'B1 15 707 x 1000 mm'),
20 ('B2' ,'B2 17 500 x 707 mm'),
21 ('B3' ,'B3 18 353 x 500 mm'),
22 ('B4' ,'B4 19 250 x 353 mm'),
23 ('B5' ,'B5 1 176 x 250 mm, 6.93 x 9.84 inches'),
24 ('B6' ,'B6 20 125 x 176 mm'),
25 ('B7' ,'B7 21 88 x 125 mm'),
26 ('B8' ,'B8 22 62 x 88 mm'),
27 ('B9' ,'B9 23 33 x 62 mm'),
28 ('B10',':B10 16 31 x 44 mm'),
29 ('C5E','C5E 24 163 x 229 mm'),
30 ('Comm10E','Comm10E 25 105 x 241 mm, U.S. Common 10 Envelope'),
31 ('DLE', 'DLE 26 110 x 220 mm'),
32 ('Executive','Executive 4 7.5 x 10 inches, 190.5 x 254 mm'),
33 ('Folio','Folio 27 210 x 330 mm'),
34 ('Ledger', 'Ledger 28 431.8 x 279.4 mm'),
35 ('Legal', 'Legal 3 8.5 x 14 inches, 215.9 x 355.6 mm'),
36 ('Letter','Letter 2 8.5 x 11 inches, 215.9 x 279.4 mm'),
37 ('Tabloid', 'Tabloid 29 279.4 x 431.8 mm'),
38 ('custom', 'Custom Paper Size'),
39 ],
40 'Paper size',
41 required=True,
42 help="Select Proper Paper size"
43 ),
44 'paper_width': fields.integer('Paper Width (mm)'),
45 'paper_height': fields.integer('Paper Height (mm)'),
46 }
47
048
=== added file 'report_webkit_custom_paper_size/header_view.xml'
--- report_webkit_custom_paper_size/header_view.xml 1970-01-01 00:00:00 +0000
+++ report_webkit_custom_paper_size/header_view.xml 2014-01-23 16:44:31 +0000
@@ -0,0 +1,17 @@
1<openerp>
2 <data>
3
4 <record model="ir.ui.view" id="header_webkit_custom_paper_size">
5 <field name="name">res.company.header.html.custom.paper.size</field>
6 <field name="model">ir.header_webkit</field>
7 <field name="inherit_id" ref="report_webkit.header_webkit"/>
8 <field name="arch" type="xml">
9 <field name="format" position="after">
10 <field name="paper_width" attrs="{'invisible': [('format', '!=', 'custom')], 'required': [('format', '=', 'custom')]}" />
11 <field name="paper_height" attrs="{'invisible': [('format', '!=', 'custom')], 'required': [('format', '=', 'custom')]}" />
12 </field>
13 </field>
14 </record>
15
16 </data>
17</openerp>