diff options
| author | Simon Lejeune <sle@openerp.com> | 2014-03-20 14:34:25 +0100 |
|---|---|---|
| committer | Simon Lejeune <sle@openerp.com> | 2014-03-20 14:34:25 +0100 |
| commit | 221d2a6eebe604c1c5ec6011533d914809bcfc3a (patch) | |
| tree | bcc7d336ba8e7e83b5f96da9022e20ab50fcaa95 /addons/report/controllers/main.py | |
| parent | 1c5a57a1296599a18303455f5e4aaa7657363e75 (diff) | |
[FIX] Reports not using the generic controller should not declare a controller anymore. They are now openerp models and are availabel either trough openerp model 'report' with get_html, get_pdf or through a controller. Adapted report_vat this way.
bzr revid: sle@openerp.com-20140320133425-z04ewof8ktjanmn9
Diffstat (limited to 'addons/report/controllers/main.py')
| -rw-r--r-- | addons/report/controllers/main.py | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/addons/report/controllers/main.py b/addons/report/controllers/main.py index a7350fdd4fe..4925374cba2 100644 --- a/addons/report/controllers/main.py +++ b/addons/report/controllers/main.py @@ -22,15 +22,20 @@ from openerp.addons.web.http import Controller, route, request import simplejson +import urlparse from werkzeug import exceptions from reportlab.graphics.barcode import createBarcodeDrawing class ReportController(Controller): + #------------------------------------------------------ + # Generic reports 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) + return request.registry['report'].get_html(request.cr, request.uid, docids, reportname, context=request.context) @route(['/report/pdf/report/<reportname>/<docids>'], type='http', auth="user", website=True) def report_pdf(self, reportname, docids): @@ -38,6 +43,30 @@ class ReportController(Controller): pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))] return request.make_response(pdf, headers=pdfhttpheaders) + #------------------------------------------------------ + # Particular reports controller + #------------------------------------------------------ + + @route(['/report/<reportname>'], type='http', auth='user', website=True, multilang=True) + def report_html_particular(self, reportname, **data): + 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) + + @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) + pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))] + return request.make_response(pdf, headers=pdfhttpheaders) + + #------------------------------------------------------ + # Misc utils + #------------------------------------------------------ + @route(['/report/barcode', '/report/barcode/<type>/<path:value>'], type='http', auth="user") def report_barcode(self, type, value, width=300, height=50): """Contoller able to render barcode images thanks to reportlab. @@ -72,9 +101,20 @@ class ReportController(Controller): requestcontent = simplejson.loads(data) url, type = requestcontent[0], requestcontent[1] if type == 'qweb-pdf': - reportname, docids = url.split('/')[-2:] - response = self.report_pdf(reportname, docids) - response.headers.add('Content-Disposition', 'attachment; filename=report.pdf;') + reportname = url.split('/report/pdf/report/')[1].split('?')[0].split('/')[0] + + if '?' not in url: + # Generic report: + docids = url.split('/')[-1] + response = self.report_pdf(reportname, docids) + else: + # Particular report: + querystring = url.split('?')[1] + querystring = urlparse.parse_qsl(querystring) + dict_querystring = dict(querystring) + response = self.report_pdf_particular(reportname, **dict_querystring) + + response.headers.add('Content-Disposition', 'attachment; filename=%s.pdf;' % reportname) response.set_cookie('fileToken', token) return response else: |
