Merge lp:~camptocamp/account-financial-report/7.0-sync-afr_webkit-with-report_webkit into lp:~account-report-core-editor/account-financial-report/7.0

Proposed by Yannick Vaucher @ Camptocamp
Status: Merged
Merged at revision: 92
Proposed branch: lp:~camptocamp/account-financial-report/7.0-sync-afr_webkit-with-report_webkit
Merge into: lp:~account-report-core-editor/account-financial-report/7.0
Diff against target: 226 lines (+52/-44)
1 file modified
account_financial_report_webkit/report/webkit_parser_header_fix.py (+52/-44)
To merge this branch: bzr merge lp:~camptocamp/account-financial-report/7.0-sync-afr_webkit-with-report_webkit
Reviewer Review Type Date Requested Status
Stéphane Bidoul (Acsone) (community) Approve
Guewen Baconnier @ Camptocamp tested Approve
Pedro Manuel Baeza code review Approve
Nicolas Bessi - Camptocamp (community) Approve
Review via email: mp+223058@code.launchpad.net

Description of the change

Adapt account_financial_report_webkit to fixes in addons

https://github.com/odoo/odoo/pull/55
https://github.com/odoo/odoo/pull/56

Plus few improvement following pep8 to remove useless variable and import

To post a comment you must log in.
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

LGTM, taking in account that previous comment on source MP are still valid.

review: Approve
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

LGTM.

Regards.

review: Approve (code review)
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Thanks

review: Approve (tested)
Revision history for this message
Stéphane Bidoul (Acsone) (sbi) wrote :

Hi,

Is it just me or this MP broke afr with ocb 7.0?

Traceback (most recent call last):
File "/home/openerp/instance/account-financial-report/account_financial_report_webkit/report/webkit_parser_header_fix.py", line 228, in create_single_pdf
**parser_instance.localcontext)
File "/home/openerp/instance/eggs/Mako-1.0.0-py2.7.egg/mako/template.py", line 443, in render
return runtime._render(self, self.callable_, args, data)
File "/home/openerp/instance/eggs/Mako-1.0.0-py2.7.egg/mako/runtime.py", line 803, in _render
**_kwargs_for_callable(callable_, data))
File "/home/openerp/instance/eggs/Mako-1.0.0-py2.7.egg/mako/runtime.py", line 835, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/openerp/instance/eggs/Mako-1.0.0-py2.7.egg/mako/runtime.py", line 860, in _exec_template
callable_(context, *args, **kwargs)
File "memory:0x5184dd0", line 22, in render_body
<%
TypeError: translate_call() takes exactly 2 arguments (3 given)

review: Needs Fixing (test)
Revision history for this message
Stéphane Bidoul (Acsone) (sbi) wrote :

reverting to rev 91 works

Revision history for this message
Stéphane Bidoul (Acsone) (sbi) wrote :

I'm using rev 5343 of ocb-server/7.0, which the latest on launchpad

Not sure what's going on. Unfortunately I can't dig deeper right now.

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

On 06/17/2014 09:29 PM, Stéphane Bidoul (Acsone) wrote:
> Review: Needs Fixing test
>
> Hi,
>
> Is it just me or this MP broke afr with ocb 7.0?
>
> Traceback (most recent call last):
> File "/home/openerp/instance/account-financial-report/account_financial_report_webkit/report/webkit_parser_header_fix.py", line 228, in create_single_pdf
> **parser_instance.localcontext)
> File "/home/openerp/instance/eggs/Mako-1.0.0-py2.7.egg/mako/template.py", line 443, in render
> return runtime._render(self, self.callable_, args, data)
> File "/home/openerp/instance/eggs/Mako-1.0.0-py2.7.egg/mako/runtime.py", line 803, in _render
> **_kwargs_for_callable(callable_, data))
> File "/home/openerp/instance/eggs/Mako-1.0.0-py2.7.egg/mako/runtime.py", line 835, in _render_context
> _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
> File "/home/openerp/instance/eggs/Mako-1.0.0-py2.7.egg/mako/runtime.py", line 860, in _exec_template
> callable_(context, *args, **kwargs)
> File "memory:0x5184dd0", line 22, in render_body
> <%
> TypeError: translate_call() takes exactly 2 arguments (3 given)
>
>

It is necessary to be compatible with this change:
https://github.com/odoo/odoo/pull/56
That has been merged in official branches.

I didn't noticed that it was not working in ocb because in my local OCB
branch (which is a bit out of date), the patch was there:

revno: 10194 [merge]
author: <email address hidden>
committer: Leonardo Pistone <email address hidden>
branch nick: 7.0-ocb
timestamp: Wed 2014-05-21 10:58:28 +0200
message:
  Transmit parser_instance using partial function for mako translation
callback.

  This to remove parser_instance from attribute as it can cause race
condition
  on cursors.

But it is no longer there when I look in the current ocb-addons tree.

I guess we should propose the MP again on OCB

--
Guewen Baconnier
Business Solutions Software Developer

Camptocamp SA
PSE A, CH-1015 Lausanne
Phone: +41 21 619 10 39
Office: +41 21 619 10 10
http://www.camptocamp.com/

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

This has been fixed by Pedro, some revision were overwritten last week and are now back in OCB.

Thanks for noticing it Stéphane

Revision history for this message
Stéphane Bidoul (Acsone) (sbi) wrote :

Tested again with ocb-addons/7.0 HEAD.

Situation is recovered. Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account_financial_report_webkit/report/webkit_parser_header_fix.py'
--- account_financial_report_webkit/report/webkit_parser_header_fix.py 2014-03-18 14:55:32 +0000
+++ account_financial_report_webkit/report/webkit_parser_header_fix.py 2014-06-13 12:07:01 +0000
@@ -30,8 +30,8 @@
30import os30import os
31import subprocess31import subprocess
32import tempfile32import tempfile
33import time
34import logging33import logging
34from functools import partial
3535
3636
37from mako import exceptions37from mako import exceptions
@@ -48,11 +48,12 @@
48# Class used only as a workaround to bug:48# Class used only as a workaround to bug:
49# http://code.google.com/p/wkhtmltopdf/issues/detail?id=65649# http://code.google.com/p/wkhtmltopdf/issues/detail?id=656
5050
51# html headers and footers do not work on big files (hundreds of pages) so we replace them by51# html headers and footers do not work on big files (hundreds of pages) so we
52# text headers and footers passed as arguments to wkhtmltopdf52# replace them by text headers and footers passed as arguments to wkhtmltopdf
53# this class has to be removed once the bug is fixed53# this class has to be removed once the bug is fixed
5454
55# in your report class, to print headers and footers as text, you have to add them in the localcontext with a key 'additional_args'55# in your report class, to print headers and footers as text, you have to add
56# them in the localcontext with a key 'additional_args'
56# for instance:57# for instance:
57# header_report_name = _('PARTNER LEDGER')58# header_report_name = _('PARTNER LEDGER')
58# footer_date_time = self.formatLang(str(datetime.today()), date_time=True)59# footer_date_time = self.formatLang(str(datetime.today()), date_time=True)
@@ -75,23 +76,25 @@
75from mako.template import Template76from mako.template import Template
76from mako.lookup import TemplateLookup77from mako.lookup import TemplateLookup
7778
79
78def mako_template(text):80def mako_template(text):
79 """Build a Mako template.81 """Build a Mako template.
8082
81 This template uses UTF-8 encoding83 This template uses UTF-8 encoding
82 """84 """
83 tmp_lookup = TemplateLookup() #we need it in order to allow inclusion and inheritance85 tmp_lookup = TemplateLookup() # we need it in order to allow inclusion and inheritance
84 return Template(text, input_encoding='utf-8', output_encoding='utf-8', lookup=tmp_lookup)86 return Template(text, input_encoding='utf-8', output_encoding='utf-8', lookup=tmp_lookup)
8587
8688
87class HeaderFooterTextWebKitParser(webkit_report.WebKitParser):89class HeaderFooterTextWebKitParser(webkit_report.WebKitParser):
8890
89 def generate_pdf(self, comm_path, report_xml, header, footer, html_list, webkit_header=False):91 def generate_pdf(self, comm_path, report_xml, header, footer, html_list,
92 webkit_header=False, parser_instance=False):
90 """Call webkit in order to generate pdf"""93 """Call webkit in order to generate pdf"""
91 if not webkit_header:94 if not webkit_header:
92 webkit_header = report_xml.webkit_header95 webkit_header = report_xml.webkit_header
93 tmp_dir = tempfile.gettempdir()96 fd, out_filename = tempfile.mkstemp(suffix=".pdf",
94 out_filename = tempfile.mktemp(suffix=".pdf", prefix="webkit.tmp.")97 prefix="webkit.tmp.")
95 file_to_del = [out_filename]98 file_to_del = [out_filename]
96 if comm_path:99 if comm_path:
97 command = [comm_path]100 command = [comm_path]
@@ -115,16 +118,16 @@
115 if webkit_header.format:118 if webkit_header.format:
116 command.extend(['--page-size', str(webkit_header.format).replace(',', '.')])119 command.extend(['--page-size', str(webkit_header.format).replace(',', '.')])
117120
118 if self.parser_instance.localcontext.get('additional_args', False):121 if parser_instance.localcontext.get('additional_args', False):
119 for arg in self.parser_instance.localcontext['additional_args']:122 for arg in parser_instance.localcontext['additional_args']:
120 command.extend(arg)123 command.extend(arg)
121124
122 count = 0125 count = 0
123 for html in html_list:126 for html in html_list:
124 html_file = file(os.path.join(tmp_dir, str(time.time()) + str(count) +'.body.html'), 'w')127 with tempfile.NamedTemporaryFile(suffix="%d.body.html" % count,
125 count += 1128 delete=False) as html_file:
126 html_file.write(html)129 count += 1
127 html_file.close()130 html_file.write(self._sanitize_html(html))
128 file_to_del.append(html_file.name)131 file_to_del.append(html_file.name)
129 command.append(html_file.name)132 command.append(html_file.name)
130 command.append(out_filename)133 command.append(out_filename)
@@ -132,8 +135,8 @@
132 file_to_del.append(stderr_path)135 file_to_del.append(stderr_path)
133 try:136 try:
134 status = subprocess.call(command, stderr=stderr_fd)137 status = subprocess.call(command, stderr=stderr_fd)
135 os.close(stderr_fd) # ensure flush before reading138 os.close(stderr_fd) # ensure flush before reading
136 stderr_fd = None # avoid closing again in finally block139 stderr_fd = None # avoid closing again in finally block
137 fobj = open(stderr_path, 'r')140 fobj = open(stderr_path, 'r')
138 error_message = fobj.read()141 error_message = fobj.read()
139 fobj.close()142 fobj.close()
@@ -142,11 +145,11 @@
142 else:145 else:
143 error_message = _('The following diagnosis message was provided:\n') + error_message146 error_message = _('The following diagnosis message was provided:\n') + error_message
144 if status:147 if status:
145 raise except_osv(_('Webkit error' ),148 raise except_osv(_('Webkit error'),
146 _("The command 'wkhtmltopdf' failed with error code = %s. Message: %s") % (status, error_message))149 _("The command 'wkhtmltopdf' failed with error code = %s. Message: %s") % (status, error_message))
147 pdf_file = open(out_filename, 'rb')150 with open(out_filename, 'rb') as pdf_file:
148 pdf = pdf_file.read()151 pdf = pdf_file.read()
149 pdf_file.close()152 os.close(fd)
150 finally:153 finally:
151 if stderr_fd is not None:154 if stderr_fd is not None:
152 os.close(stderr_fd)155 os.close(stderr_fd)
@@ -160,57 +163,60 @@
160 # override needed to keep the attachments' storing procedure163 # override needed to keep the attachments' storing procedure
161 def create_single_pdf(self, cursor, uid, ids, data, report_xml, context=None):164 def create_single_pdf(self, cursor, uid, ids, data, report_xml, context=None):
162 """generate the PDF"""165 """generate the PDF"""
166
163 if context is None:167 if context is None:
164 context={}168 context = {}
165 htmls = []169 htmls = []
166 if report_xml.report_type != 'webkit':170 if report_xml.report_type != 'webkit':
167 return super(HeaderFooterTextWebKitParser,self).create_single_pdf(cursor, uid, ids, data, report_xml, context=context)171 return super(HeaderFooterTextWebKitParser, self
172 ).create_single_pdf(cursor, uid, ids, data,
173 report_xml, context=context)
168174
169 self.parser_instance = self.parser(cursor,175 parser_instance = self.parser(cursor,
170 uid,176 uid,
171 self.name2,177 self.name2,
172 context=context)178 context=context)
173179
174 self.pool = pooler.get_pool(cursor.dbname)180 self.pool = pooler.get_pool(cursor.dbname)
175 objs = self.getObjects(cursor, uid, ids, context)181 objs = self.getObjects(cursor, uid, ids, context)
176 self.parser_instance.set_context(objs, data, ids, report_xml.report_type)182 parser_instance.set_context(objs, data, ids, report_xml.report_type)
177183
178 template = False184 template = False
179185
180 if report_xml.report_file:186 if report_xml.report_file:
181 path = addons.get_module_resource(*report_xml.report_file.split(os.path.sep))187 path = addons.get_module_resource(*report_xml.report_file.split(os.path.sep))
182 if os.path.exists(path):188 if os.path.exists(path):
183 template = file(path).read()189 template = file(path).read()
184 if not template and report_xml.report_webkit_data:190 if not template and report_xml.report_webkit_data:
185 template = report_xml.report_webkit_data191 template = report_xml.report_webkit_data
186 if not template:192 if not template:
187 raise except_osv(_('Error!'), _('Webkit Report template not found !'))193 raise except_osv(_('Error!'), _('Webkit Report template not found !'))
188 header = report_xml.webkit_header.html194 header = report_xml.webkit_header.html
189 footer = report_xml.webkit_header.footer_html195
190 if not header and report_xml.header:196 if not header and report_xml.header:
191 raise except_osv(197 raise except_osv(
192 _('No header defined for this Webkit report!'),198 _('No header defined for this Webkit report!'),
193 _('Please set a header in company settings')199 _('Please set a header in company settings.')
194 )200 )
195201
196 css = report_xml.webkit_header.css202 css = report_xml.webkit_header.css
197 if not css:203 if not css:
198 css = ''204 css = ''
199 user = self.pool.get('res.users').browse(cursor, uid, uid)
200205
206 translate_call = partial(self.translate_call, parser_instance)
201 #default_filters=['unicode', 'entity'] can be used to set global filter207 #default_filters=['unicode', 'entity'] can be used to set global filter
202 body_mako_tpl = mako_template(template)208 body_mako_tpl = mako_template(template)
203 helper = WebKitHelper(cursor, uid, report_xml.id, context)209 helper = WebKitHelper(cursor, uid, report_xml.id, context)
204 if report_xml.precise_mode:210 if report_xml.precise_mode:
205 for obj in objs:211 for obj in objs:
206 self.parser_instance.localcontext['objects'] = [obj]212 parser_instance.localcontext['objects'] = [obj]
207 try:213 try:
208 html = body_mako_tpl.render(helper=helper,214 html = body_mako_tpl.render(helper=helper,
209 css=css,215 css=css,
210 _=self.translate_call,216 _=translate_call,
211 **self.parser_instance.localcontext)217 **parser_instance.localcontext)
212 htmls.append(html)218 htmls.append(html)
213 except Exception, e:219 except Exception:
214 msg = exceptions.text_error_template().render()220 msg = exceptions.text_error_template().render()
215 _logger.error(msg)221 _logger.error(msg)
216 raise except_osv(_('Webkit render'), msg)222 raise except_osv(_('Webkit render'), msg)
@@ -218,15 +224,16 @@
218 try:224 try:
219 html = body_mako_tpl.render(helper=helper,225 html = body_mako_tpl.render(helper=helper,
220 css=css,226 css=css,
221 _=self.translate_call,227 _=translate_call,
222 **self.parser_instance.localcontext)228 **parser_instance.localcontext)
223 htmls.append(html)229 htmls.append(html)
224 except Exception, e:230 except Exception:
225 msg = exceptions.text_error_template().render()231 msg = exceptions.text_error_template().render()
226 _logger.error(msg)232 _logger.error(msg)
227 raise except_osv(_('Webkit render'), msg)233 raise except_osv(_('Webkit render'), msg)
228234
229 # NO html footer and header because we write them as text with wkhtmltopdf235 # NO html footer and header because we write them as text with
236 # wkhtmltopdf
230 head = foot = False237 head = foot = False
231238
232 if report_xml.webkit_debug:239 if report_xml.webkit_debug:
@@ -234,13 +241,14 @@
234 deb = body_mako_tpl.render(helper=helper,241 deb = body_mako_tpl.render(helper=helper,
235 css=css,242 css=css,
236 _debug=tools.ustr("\n".join(htmls)),243 _debug=tools.ustr("\n".join(htmls)),
237 _=self.translate_call,244 _=translate_call,
238 **self.parser_instance.localcontext)245 **parser_instance.localcontext)
239 except Exception, e:246 except Exception:
240 msg = exceptions.text_error_template().render()247 msg = exceptions.text_error_template().render()
241 _logger.error(msg)248 _logger.error(msg)
242 raise except_osv(_('Webkit render'), msg)249 raise except_osv(_('Webkit render'), msg)
243 return (deb, 'html')250 return (deb, 'html')
244 bin = self.get_lib(cursor, uid)251 bin = self.get_lib(cursor, uid)
245 pdf = self.generate_pdf(bin, report_xml, head, foot, htmls)252 pdf = self.generate_pdf(bin, report_xml, head, foot, htmls,
253 parser_instance=parser_instance)
246 return (pdf, 'pdf')254 return (pdf, 'pdf')

Subscribers

People subscribed via source and target branches

to status/vote changes: