[FIX] get_pdf can be called on is own (no need to call get_html before on particular controller-report) and make the multiple ids work

bzr revid: sle@openerp.com-20140320140609-7ozly6f55sgeow7k
This commit is contained in:
Simon Lejeune 2014-03-20 15:06:09 +01:00
parent 221d2a6eeb
commit 52522bf0f9
2 changed files with 13 additions and 11 deletions

View File

@ -35,11 +35,13 @@ class ReportController(Controller):
@route(['/report/<reportname>/<docids>'], type='http', auth='user', website=True, multilang=True)
def report_html(self, reportname, docids):
return request.registry['report'].get_html(request.cr, request.uid, docids, reportname, context=request.context)
cr, uid, context = request.cr, request.uid, request.context
return request.registry['report'].get_html(cr, uid, docids, reportname, context=context)
@route(['/report/pdf/report/<reportname>/<docids>'], type='http', auth="user", website=True)
def report_pdf(self, reportname, docids):
pdf = request.registry['report'].get_pdf(request.cr, request.uid, docids, reportname)
cr, uid, context = request.cr, request.uid, request.context
pdf = request.registry['report'].get_pdf(cr, uid, docids, reportname, context=context)
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))]
return request.make_response(pdf, headers=pdfhttpheaders)
@ -49,17 +51,17 @@ class ReportController(Controller):
@route(['/report/<reportname>'], type='http', auth='user', website=True, multilang=True)
def report_html_particular(self, reportname, **data):
cr, uid, context = request.cr, request.uid, request.context
report_obj = request.registry['report']
data = report_obj.eval_params(data)
return report_obj.get_html(request.cr, request.uid, [], reportname, data=data, context=request.context)
data = report_obj.eval_params(data) # Sanitizing
return report_obj.get_html(cr, uid, [], reportname, data=data, context=context)
@route(['/report/pdf/report/<reportname>'], type='http', auth='user', website=True, multilang=True)
def report_pdf_particular(self, reportname, **data):
cr, uid, context = request.cr, request.uid, request.context
report_obj = request.registry['report']
data = report_obj.eval_params(data)
html = report_obj.get_html(cr, uid, [], reportname, data=data, context=context)
pdf = report_obj.get_pdf(cr, uid, [], reportname, html=html, context=context)
data = report_obj.eval_params(data) # Sanitizing
pdf = report_obj.get_pdf(cr, uid, [], reportname, data=data, context=context)
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))]
return request.make_response(pdf, headers=pdfhttpheaders)

View File

@ -236,7 +236,7 @@ class Report(osv.Model):
except:
pass
if isinstance(ids, str):
if isinstance(ids, (str, unicode)):
ids = [int(i) for i in ids.split(',')]
if isinstance(ids, list):
ids = list(set(ids))
@ -254,7 +254,7 @@ class Report(osv.Model):
}
return self.render(cr, uid, [], report.report_name, docargs, context=context)
def get_pdf(self, cr, uid, ids, report_name, html=None, context=None):
def get_pdf(self, cr, uid, ids, report_name, html=None, data=None, context=None):
"""This method generates and returns pdf version of generic report.
"""
if context is None:
@ -268,7 +268,7 @@ class Report(osv.Model):
ids = [ids]
if html is None:
html = self.get_html(cr, uid, ids, report_name, context=context)
html = self.get_html(cr, uid, ids, report_name, data=data, context=context)
html = html.decode('utf-8')
@ -644,7 +644,7 @@ class Report(osv.Model):
document.close()
merged = cStringIO.StringIO()
writer.write(merged)
merged.flush()
merged.seek(0)
content = merged.read()
merged.close()
return content