Merge lp:~openerp-dev/openobject-server/trunk-bug-516966-ysa into lp:openobject-server

Proposed by Yogesh (SerpentCS)
Status: Work in progress
Proposed branch: lp:~openerp-dev/openobject-server/trunk-bug-516966-ysa
Merge into: lp:openobject-server
Diff against target: 63 lines (+19/-14)
2 files modified
openerp/report/render/rml2pdf/trml2pdf.py (+1/-1)
openerp/report/report_sxw.py (+18/-13)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/trunk-bug-516966-ysa
Reviewer Review Type Date Requested Status
Naresh(OpenERP) (community) Needs Fixing
Raphael Collet (OpenERP) (community) Needs Fixing
Vo Minh Thu Pending
Review via email: mp+62127@code.launchpad.net

Description of the change

fix problem of <pageCount/> tag in rml file.

To post a comment you must log in.
Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

this will give the uniform behaviour whether the attachments are kept or not also there is no need of explicitly adding <pageNumberReset> before the <story> tag in rml's.

Thanks

review: Approve
Revision history for this message
Raphael Collet (OpenERP) (rco-openerp) wrote :

This breaks the test hr_attendance_error. The generation of report "hr.attendance.error" invokes the method report_sxw.create_source_pdf with ids=[] (the ids are provided through the field "datas".) In that case, the method returns None.

The problem is in the method _rml_template.render (openerp/report/render/trml2pdf.py). The element pageCount is rendered only once for all tags <story>, while each story should have its own value for pageCount. Moreover, pageCount is rendered after a PageReset, which explains why the value is 0...

Raphael

review: Needs Fixing
Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

yes...also the code would not work for the report other then *PDF*.

review: Needs Fixing

Unmerged revisions

3426. By Yogesh (SerpentCS)

[FIX] fix problem of <pageCount/> tag in rml file.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/report/render/rml2pdf/trml2pdf.py'
2--- openerp/report/render/rml2pdf/trml2pdf.py 2011-05-06 09:39:20 +0000
3+++ openerp/report/render/rml2pdf/trml2pdf.py 2011-05-24 13:37:28 +0000
4@@ -118,7 +118,7 @@
5 def draw(self):
6 self.canv.beginForm("pageCount")
7 self.canv.setFont("Helvetica", utils.unit_get(str(8)))
8- self.canv.drawString(0, 0, str(self.canv.getPageNumber()))
9+ self.canv.drawString(0, 0, str(self.canv._pageCount))
10 self.canv.endForm()
11
12 class PageReset(platypus.Flowable):
13
14=== modified file 'openerp/report/report_sxw.py'
15--- openerp/report/report_sxw.py 2011-05-09 08:46:41 +0000
16+++ openerp/report/report_sxw.py 2011-05-24 13:37:28 +0000
17@@ -445,9 +445,9 @@
18 context={}
19 pool = pooler.get_pool(cr.dbname)
20 attach = report_xml.attachment
21+ results = []
22 if attach:
23 objs = self.getObjects(cr, uid, ids, context)
24- results = []
25 for obj in objs:
26 aname = eval(attach, {'object':obj, 'time':time})
27 result = False
28@@ -478,18 +478,23 @@
29 #TODO: should probably raise a proper osv_except instead, shouldn't we? see LP bug #325632
30 logging.getLogger('report').error('Could not create saved report attachment', exc_info=True)
31 results.append(result)
32- if results:
33- if results[0][1]=='pdf':
34- from pyPdf import PdfFileWriter, PdfFileReader
35- output = PdfFileWriter()
36- for r in results:
37- reader = PdfFileReader(cStringIO.StringIO(r[0]))
38- for page in range(reader.getNumPages()):
39- output.addPage(reader.getPage(page))
40- s = cStringIO.StringIO()
41- output.write(s)
42- return s.getvalue(), results[0][1]
43- return self.create_single_pdf(cr, uid, ids, data, report_xml, context)
44+ else:
45+ for id in ids:
46+ result = self.create_single_pdf(cr, uid, [id], data, report_xml, context)
47+ if not result:
48+ return False
49+ results.append(result)
50+ if results:
51+ if results[0][1]=='pdf':
52+ from pyPdf import PdfFileWriter, PdfFileReader
53+ output = PdfFileWriter()
54+ for r in results:
55+ reader = PdfFileReader(cStringIO.StringIO(r[0]))
56+ for page in range(reader.getNumPages()):
57+ output.addPage(reader.getPage(page))
58+ s = cStringIO.StringIO()
59+ output.write(s)
60+ return s.getvalue(), results[0][1]
61
62 def create_single_pdf(self, cr, uid, ids, data, report_xml, context=None):
63 if not context: