[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
This commit is contained in:
parent
1c5a57a129
commit
221d2a6eeb
|
@ -19,6 +19,7 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv import osv
|
||||
from openerp.addons.web import http
|
||||
from openerp.addons.web.http import request
|
||||
from common_report_header import common_report_header
|
||||
|
@ -29,14 +30,12 @@ except ImportError:
|
|||
import xlwt
|
||||
|
||||
|
||||
class tax_report(http.Controller, common_report_header):
|
||||
class tax_report(osv.Model, common_report_header):
|
||||
_name = 'report.account.report_vat'
|
||||
|
||||
@http.route(['/report/account.report_vat', '/report/pdf/report/account.report_vat'], type='http', auth='user', website=True, multilang=True)
|
||||
def report_account_tax(self, **data):
|
||||
def render_html(self, cr, uid, ids, data=None, context=None):
|
||||
report_obj = request.registry['report']
|
||||
self.cr, self.uid, self.pool = request.cr, request.uid, request.registry
|
||||
|
||||
data = report_obj.eval_params(data)
|
||||
self.cr, self.uid = cr, uid
|
||||
|
||||
res = {}
|
||||
self.period_ids = []
|
||||
|
@ -56,12 +55,7 @@ class tax_report(http.Controller, common_report_header):
|
|||
'period_to': self.get_end_period(data),
|
||||
'taxlines': self._get_lines(self._get_basedon(data), company_id=data['form']['company_id']),
|
||||
}
|
||||
if request.httprequest.path.startswith('/report/pdf/'):
|
||||
html = request.registry['report'].render(self.cr, self.uid, [], 'account.report_vat', docargs)
|
||||
pdf = request.registry['report'].get_pdf(self.cr, self.uid, [], 'account.report_vat', html=html)
|
||||
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))]
|
||||
return request.make_response(pdf, headers=pdfhttpheaders)
|
||||
return request.registry['report'].render(self.cr, self.uid, [], 'account.report_vat', docargs)
|
||||
return report_obj.render(self.cr, self.uid, [], 'account.report_vat', docargs)
|
||||
|
||||
def _get_basedon(self, form):
|
||||
return form['form']['based_on']
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -220,10 +220,22 @@ class Report(osv.Model):
|
|||
# Public report API
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
def get_html(self, cr, uid, ids, report_name, context=None):
|
||||
def get_html(self, cr, uid, ids, report_name, data=None, context=None):
|
||||
"""This method generates and returns html version of generic report.
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
# If the report is using a custom model to render its html, we must use it.
|
||||
# Otherwise, fallback on the generic html rendering.
|
||||
if data is not None:
|
||||
try:
|
||||
report_model_name = 'report.%s' % report_name
|
||||
particularreport_obj = self.pool[report_model_name]
|
||||
return particularreport_obj.render_html(cr, uid, [], data=data, context=context)
|
||||
except:
|
||||
pass
|
||||
|
||||
if isinstance(ids, str):
|
||||
ids = [int(i) for i in ids.split(',')]
|
||||
if isinstance(ids, list):
|
||||
|
@ -243,11 +255,21 @@ 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):
|
||||
"""This method generates and returns pdf version of generic report.
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
if isinstance(ids, (str, unicode)):
|
||||
ids = [int(i) for i in ids.split(',')]
|
||||
if isinstance(ids, list):
|
||||
ids = list(set(ids))
|
||||
if isinstance(ids, int):
|
||||
ids = [ids]
|
||||
|
||||
if html is None:
|
||||
html = self.get_html(cr, uid, ids, report_name, context=context)
|
||||
|
||||
html = html.decode('utf-8')
|
||||
|
||||
# Get the report we are working on.
|
||||
|
@ -628,7 +650,7 @@ class Report(osv.Model):
|
|||
return content
|
||||
|
||||
def eval_params(self, dict_param):
|
||||
"""Parse a dictionary generated by the webclient (javascript) into a dictionary
|
||||
"""Parse a dict generated by the webclient (javascript) into a dictionary
|
||||
understandable by a wizard controller (python).
|
||||
"""
|
||||
for key, value in dict_param.iteritems():
|
||||
|
|
Loading…
Reference in New Issue