Merge lp:~openerp-dev/openobject-server/6.0-opw-572488-rha into lp:openobject-server/6.0

Proposed by Rifakat Husen (OpenERP)
Status: Merged
Approved by: Naresh(OpenERP)
Approved revision: 3611
Merged at revision: 3651
Proposed branch: lp:~openerp-dev/openobject-server/6.0-opw-572488-rha
Merge into: lp:openobject-server/6.0
Diff against target: 43 lines (+18/-6)
1 file modified
bin/report/report_sxw.py (+18/-6)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/6.0-opw-572488-rha
Reviewer Review Type Date Requested Status
Naresh(OpenERP) (community) Approve
Review via email: mp+98580@code.launchpad.net

Description of the change

Hello,

Fix for duplication of the content of sxw report. When report type is sxw, it duplicates contents in zip while writing using writestr().

To reproduce this,
1. Open any report from menu "Reports",(ex: Model Overview)
2. Set "Report Type" = sxw
3. Open this report
3. Save sxw and open saved sxw with archive editor to see multiple contents into archive.

Created an empty zip file and write report contents after checking and avoid duplication.

Please review it.

Regards,
Rifakat

To post a comment you must log in.
3610. By Launchpad Translations on behalf of openerp

Launchpad automatic translations update.

3611. By Rifakat Husen (OpenERP)

[FIX] report: fix for currupt sxw

Revision history for this message
Naresh(OpenERP) (nch-openerp) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/report/report_sxw.py'
2--- bin/report/report_sxw.py 2011-10-13 12:12:25 +0000
3+++ bin/report/report_sxw.py 2012-03-27 13:35:24 +0000
4@@ -586,10 +586,9 @@
5 create_doc = self.generators[mime_type]
6 odt = etree.tostring(create_doc(rml_dom, rml_parser.localcontext),
7 encoding='utf-8', xml_declaration=True)
8- sxw_z = zipfile.ZipFile(sxw_io, mode='a')
9- sxw_z.writestr('content.xml', odt)
10- sxw_z.writestr('meta.xml', meta)
11-
12+
13+ sxw_contents = {'content.xml':odt, 'meta.xml':meta}
14+
15 if report_xml.header:
16 #Add corporate header/footer
17 rml_file = tools.file_open(os.path.join('base', 'report', 'corporate_%s_header.xml' % report_type))
18@@ -607,11 +606,24 @@
19 rml_parser._add_header(odt)
20 odt = etree.tostring(odt, encoding='utf-8',
21 xml_declaration=True)
22- sxw_z.writestr('styles.xml', odt)
23+ sxw_contents['styles.xml'] = odt
24 finally:
25 rml_file.close()
26+
27+ #created empty zip writing sxw contents to avoid duplication
28+ sxw_out = StringIO.StringIO()
29+ sxw_z = zipfile.ZipFile(sxw_out, mode='w')
30+
31+ zin = zipfile.ZipFile (sxw_io, 'r')
32+ for item in zin.infolist():
33+ if item.filename not in sxw_contents.keys():
34+ buffer = zin.read(item.filename)
35+ sxw_z.writestr(item.filename, buffer)
36+ for item, buffer in sxw_contents.iteritems():
37+ sxw_z.writestr(item, buffer)
38+
39 sxw_z.close()
40- final_op = sxw_io.getvalue()
41+ final_op = sxw_out.getvalue()
42 sxw_io.close()
43 return (final_op, mime_type)
44