2014-02-12 18:00:25 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2014-Today OpenERP SA (<http://www.openerp.com>).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2014-03-19 18:36:14 +00:00
|
|
|
from openerp.addons.web.http import Controller, route, request
|
[REM] removed details_summary, sales_user, sales_user_today, payment_user reports, wizards and rml
[REM] dead code: pos_box_entries.py/xml, pos_box_out.py/xml, pos_return_view.py/xml
[ADD] lines, invoice, cashbox of the day, payment, receipt, users product reports converted to QWeb. Added YML tests for the bank statement reports.
[FIX] closed cashbox of the day sql using old fields in its queries, yml test not correctly generating an invoice from a pos order
bzr revid: sle@openerp.com-20140414104954-xj10wi640tyr3ufe
2014-04-14 10:49:54 +00:00
|
|
|
from openerp.addons.web.controllers.main import _serialize_exception
|
|
|
|
from openerp.osv import osv
|
2014-02-12 18:00:25 +00:00
|
|
|
|
2014-02-18 12:53:22 +00:00
|
|
|
import simplejson
|
2014-04-02 16:23:44 +00:00
|
|
|
from werkzeug import exceptions, url_decode
|
|
|
|
from werkzeug.test import Client
|
|
|
|
from werkzeug.wrappers import BaseResponse
|
|
|
|
from werkzeug.datastructures import Headers
|
2014-02-24 12:07:49 +00:00
|
|
|
from reportlab.graphics.barcode import createBarcodeDrawing
|
2014-02-12 18:09:34 +00:00
|
|
|
|
|
|
|
|
2014-03-19 18:36:14 +00:00
|
|
|
class ReportController(Controller):
|
2014-02-12 18:09:34 +00:00
|
|
|
|
2014-03-20 13:34:25 +00:00
|
|
|
#------------------------------------------------------
|
2014-04-02 16:23:44 +00:00
|
|
|
# Report controllers
|
2014-03-20 13:34:25 +00:00
|
|
|
#------------------------------------------------------
|
2014-04-02 16:23:44 +00:00
|
|
|
@route([
|
|
|
|
'/report/<path:converter>/<reportname>',
|
|
|
|
'/report/<path:converter>/<reportname>/<docids>',
|
2014-05-13 09:35:45 +00:00
|
|
|
], type='http', auth='user', website=True)
|
2014-04-02 16:23:44 +00:00
|
|
|
def report_routes(self, reportname, docids=None, converter=None, **data):
|
2014-03-20 13:34:25 +00:00
|
|
|
report_obj = request.registry['report']
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
2014-04-02 16:23:44 +00:00
|
|
|
|
|
|
|
if docids:
|
|
|
|
docids = [int(i) for i in docids.split(',')]
|
|
|
|
options_data = None
|
|
|
|
if data.get('options'):
|
|
|
|
options_data = simplejson.loads(data['options'])
|
|
|
|
if data.get('context'):
|
2014-06-27 10:00:49 +00:00
|
|
|
# Ignore 'lang' here, because the context in data is the one from the webclient *but* if
|
|
|
|
# the user explicitely wants to change the lang, this mechanism overwrites it.
|
|
|
|
data_context = simplejson.loads(data['context'])
|
|
|
|
if data_context.get('lang'):
|
|
|
|
del data_context['lang']
|
|
|
|
context.update(data_context)
|
2014-04-02 16:23:44 +00:00
|
|
|
|
|
|
|
if converter == 'html':
|
|
|
|
html = report_obj.get_html(cr, uid, docids, reportname, data=options_data, context=context)
|
|
|
|
return request.make_response(html)
|
|
|
|
elif converter == 'pdf':
|
|
|
|
pdf = report_obj.get_pdf(cr, uid, docids, reportname, data=options_data, context=context)
|
|
|
|
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))]
|
|
|
|
return request.make_response(pdf, headers=pdfhttpheaders)
|
|
|
|
else:
|
|
|
|
raise exceptions.HTTPException(description='Converter %s not implemented.' % converter)
|
2014-03-20 13:34:25 +00:00
|
|
|
|
|
|
|
#------------------------------------------------------
|
2014-03-21 10:58:06 +00:00
|
|
|
# Misc. route utils
|
2014-03-20 13:34:25 +00:00
|
|
|
#------------------------------------------------------
|
2014-03-19 18:36:14 +00:00
|
|
|
@route(['/report/barcode', '/report/barcode/<type>/<path:value>'], type='http', auth="user")
|
2014-05-21 10:59:05 +00:00
|
|
|
def report_barcode(self, type, value, width=600, height=100):
|
2014-02-20 11:13:23 +00:00
|
|
|
"""Contoller able to render barcode images thanks to reportlab.
|
2014-02-21 16:33:20 +00:00
|
|
|
Samples:
|
|
|
|
<img t-att-src="'/report/barcode/QR/%s' % o.name"/>
|
2014-03-21 10:58:06 +00:00
|
|
|
<img t-att-src="'/report/barcode/?type=%s&value=%s&width=%s&height=%s' %
|
|
|
|
('QR', o.name, 200, 200)"/>
|
2014-02-20 11:13:23 +00:00
|
|
|
|
|
|
|
:param type: Accepted types: 'Codabar', 'Code11', 'Code128', 'EAN13', 'EAN8', 'Extended39',
|
2014-02-19 14:26:49 +00:00
|
|
|
'Extended93', 'FIM', 'I2of5', 'MSI', 'POSTNET', 'QR', 'Standard39', 'Standard93',
|
|
|
|
'UPCA', 'USPS_4State'
|
|
|
|
"""
|
|
|
|
try:
|
2014-02-21 16:33:20 +00:00
|
|
|
width, height = int(width), int(height)
|
2014-02-24 12:07:49 +00:00
|
|
|
barcode = createBarcodeDrawing(
|
2014-02-21 10:15:20 +00:00
|
|
|
type, value=value, format='png', width=width, height=height
|
2014-02-20 11:13:23 +00:00
|
|
|
)
|
2014-02-24 12:07:49 +00:00
|
|
|
barcode = barcode.asString('png')
|
2014-02-19 14:26:49 +00:00
|
|
|
except (ValueError, AttributeError):
|
2014-02-20 11:13:23 +00:00
|
|
|
raise exceptions.HTTPException(description='Cannot convert into barcode.')
|
2014-02-19 14:26:49 +00:00
|
|
|
|
2014-02-21 10:15:20 +00:00
|
|
|
return request.make_response(barcode, headers=[('Content-Type', 'image/png')])
|
2014-02-21 16:33:20 +00:00
|
|
|
|
2014-03-21 12:21:03 +00:00
|
|
|
@route(['/report/download'], type='http', auth="user", website=True)
|
2014-03-19 18:36:14 +00:00
|
|
|
def report_download(self, data, token):
|
2014-02-24 10:33:29 +00:00
|
|
|
"""This function is used by 'qwebactionmanager.js' in order to trigger the download of
|
2014-04-02 16:23:44 +00:00
|
|
|
a pdf/controller report.
|
2014-02-21 16:33:20 +00:00
|
|
|
|
2014-03-19 18:36:14 +00:00
|
|
|
:param data: a javascript array JSON.stringified containg report internal url ([0]) and
|
2014-02-24 10:33:29 +00:00
|
|
|
type [1]
|
2014-02-21 16:33:20 +00:00
|
|
|
:returns: Response with a filetoken cookie and an attachment header
|
|
|
|
"""
|
|
|
|
requestcontent = simplejson.loads(data)
|
|
|
|
url, type = requestcontent[0], requestcontent[1]
|
[REM] removed details_summary, sales_user, sales_user_today, payment_user reports, wizards and rml
[REM] dead code: pos_box_entries.py/xml, pos_box_out.py/xml, pos_return_view.py/xml
[ADD] lines, invoice, cashbox of the day, payment, receipt, users product reports converted to QWeb. Added YML tests for the bank statement reports.
[FIX] closed cashbox of the day sql using old fields in its queries, yml test not correctly generating an invoice from a pos order
bzr revid: sle@openerp.com-20140414104954-xj10wi640tyr3ufe
2014-04-14 10:49:54 +00:00
|
|
|
try:
|
|
|
|
if type == 'qweb-pdf':
|
|
|
|
reportname = url.split('/report/pdf/')[1].split('?')[0]
|
|
|
|
|
|
|
|
docids = None
|
|
|
|
if '/' in reportname:
|
|
|
|
reportname, docids = reportname.split('/')
|
|
|
|
|
|
|
|
if docids:
|
|
|
|
# Generic report:
|
|
|
|
response = self.report_routes(reportname, docids=docids, converter='pdf')
|
|
|
|
else:
|
|
|
|
# Particular report:
|
|
|
|
data = url_decode(url.split('?')[1]).items() # decoding the args represented in JSON
|
|
|
|
response = self.report_routes(reportname, converter='pdf', **dict(data))
|
|
|
|
|
|
|
|
response.headers.add('Content-Disposition', 'attachment; filename=%s.pdf;' % reportname)
|
|
|
|
response.set_cookie('fileToken', token)
|
|
|
|
return response
|
|
|
|
elif type =='controller':
|
|
|
|
reqheaders = Headers(request.httprequest.headers)
|
|
|
|
response = Client(request.httprequest.app, BaseResponse).get(url, headers=reqheaders, follow_redirects=True)
|
|
|
|
response.set_cookie('fileToken', token)
|
|
|
|
return response
|
2014-03-20 13:34:25 +00:00
|
|
|
else:
|
[REM] removed details_summary, sales_user, sales_user_today, payment_user reports, wizards and rml
[REM] dead code: pos_box_entries.py/xml, pos_box_out.py/xml, pos_return_view.py/xml
[ADD] lines, invoice, cashbox of the day, payment, receipt, users product reports converted to QWeb. Added YML tests for the bank statement reports.
[FIX] closed cashbox of the day sql using old fields in its queries, yml test not correctly generating an invoice from a pos order
bzr revid: sle@openerp.com-20140414104954-xj10wi640tyr3ufe
2014-04-14 10:49:54 +00:00
|
|
|
return
|
|
|
|
except osv.except_osv, e:
|
|
|
|
se = _serialize_exception(e)
|
|
|
|
error = {
|
|
|
|
'code': 200,
|
|
|
|
'message': "OpenERP Server Error",
|
|
|
|
'data': se
|
|
|
|
}
|
|
|
|
return request.make_response(simplejson.dumps(error))
|
2014-02-21 16:33:20 +00:00
|
|
|
|
2014-03-19 18:36:14 +00:00
|
|
|
@route(['/report/check_wkhtmltopdf'], type='json', auth="user")
|
2014-02-27 14:48:10 +00:00
|
|
|
def check_wkhtmltopdf(self):
|
2014-03-21 16:47:16 +00:00
|
|
|
return request.registry['report']._check_wkhtmltopdf()
|