def report_download(self, data, token): """This function is used by 'qwebactionmanager.js' in order to trigger the download of a pdf/controller report. :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = simplejson.loads(data) url, type = requestcontent[0], requestcontent[1] try: if type == 'qweb-pdf': reportname = url.split('/report/pdf/')[1].split('?')[0] docids = None if '/' in reportname: reportname, docids = reportname.split('/') attach_name = reportname if docids: so_ids = [int(i) for i in docids.split(',')] if reportname.find( 'cebis_sale_order_report.report_sale_order') != -1: cr, uid, context = request.cr, request.uid, request.context so = request.registry['sale.order'].browse( cr, uid, so_ids, context=context)[0] attach_name = so.name # 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;' % attach_name) 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 else: return except Exception, e: se = _serialize_exception(e) error = {'code': 200, 'message': "Odoo Server Error", 'data': se} return request.make_response(html_escape(simplejson.dumps(error)))
def wrap(*args, **kwargs): try: return f(*args, **kwargs) except Exception, e: _logger.exception("An exception occured during an http request") se = _serialize_exception(e) error = {'code': 200, 'message': "Odoo Server Error", 'data': se} return werkzeug.exceptions.InternalServerError( simplejson.dumps(error))
def report_download(self, data, token): """This function is used by 'qwebactionmanager.js' in order to trigger the download of a pdf/controller report. :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = simplejson.loads(data) url, type = requestcontent[0], requestcontent[1] 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 = super(Extension, self).report_routes(reportname, docids=docids, converter='pdf') # response = self.report_routes(reportname, docids=docids, converter='pdf') ##### FIX START: switch reportname with the evaluated attachment attribute of the action if available docids = [int(i) for i in docids.split(',')] report_obj = request.registry['report'] cr, uid, context = request.cr, request.uid, request.context report = report_obj._get_report_from_name(cr, uid, reportname) obj = report_obj.pool[report.model].browse(cr, uid, docids[0]) if hasattr(obj, 'name') and obj.name: reportname = obj.name ##### FIX END else: # Particular report: data = url_decode(url.split('?')[1]).items() # decoding the args represented in JSON response = super(Extension, self).report_routes(reportname, converter='pdf', **dict(data)) # 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 else: return except Exception, e: se = _serialize_exception(e) error = { 'code': 200, 'message': "Odoo Server Error", 'data': se } return request.make_response(html_escape(simplejson.dumps(error)))
def report_download(self, data, token): """This function is used by 'qwebactionmanager.js' in order to trigger the download of a pdf/controller report. :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = simplejson.loads(data) url, type = requestcontent[0], requestcontent[1] 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)) cr, uid, context = request.cr, openerp.SUPERUSER_ID, request.context report_obj = request.registry['ir.actions.report.xml'] idreport = report_obj.search(cr, uid, [('report_name', '=', reportname)], context=context) try: report = report_obj.browse(cr, uid, idreport[0], context=context) reportname = report.report_file + '_' + time.strftime('%Y%m%d', time.gmtime()) except IndexError: _logger.error("Can not lookup report %s" % reportname) 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 else: return except Exception, e: se = _serialize_exception(e) error = { 'code': 200, 'message': "Odoo Server Error", 'data': se } return request.make_response(html_escape(simplejson.dumps(error)))
def report_download(self, data,token): """This function is used by 'qwebactionmanager.js' in order to trigger the download of a pdf/controller report. :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = simplejson.loads(data) url, type = requestcontent[0], requestcontent[1] 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)) if reportname == 'jjuice_fedex.report_print_label': cr, context = request.cr, request.context info = request.registry('create.shipment.fedex').read(cr,SUPERUSER_ID,int(docids),['to_person_name','tracking_number']) str_list = [] str_list.append(time.strftime("%Y-%m-%d")) str_list.append(info.get('to_person_name','unavailable') or 'unavailable') str_list.append(info.get('tracking_number','unavailable') or 'unavailable') label_name = '_'.join(str_list) response.headers.add('Content-Disposition', 'attachment; filename=%s.pdf;' % label_name) else: 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 else: return except Exception, e: se = _serialize_exception(e) error = { 'code': 200, 'message': "Odoo Server Error", 'data': se } return request.make_response(html_escape(simplejson.dumps(error)))
def report_download(self, data, token): """This function is used by 'qwebactionmanager.js' in order to trigger the download of a pdf/controller report. :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = simplejson.loads(data) url, type = requestcontent[0], requestcontent[1] try: if type == 'qweb-pdf': reportname = url.split('/report/pdf/')[1].split('?')[0] docids = None if '/' in reportname: reportname, docids = reportname.split('/') print docids,reportname 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)) #Rename the pdf's name make it looks kindly. report_ids = request.registry.get('ir.actions.report.xml').search(request.cr,openerp.SUPERUSER_ID,[('report_name','=',reportname)]) if len(report_ids): report_obj = request.registry.get('ir.actions.report.xml').browse(request.cr,openerp.SUPERUSER_ID,report_ids[0]) docids = [int(x) for x in docids.split(',')] reports = request.registry.get(report_obj.model).browse(request.cr,openerp.SUPERUSER_ID,docids) filename = reports[0].name response.headers.add('Content-Disposition', 'attachment; filename=%s.pdf;' % filename) 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 else: return except Exception, e: se = _serialize_exception(e) error = { 'code': 200, 'message': "Odoo Server Error", 'data': se } return request.make_response(html_escape(simplejson.dumps(error)))
def report_download(self, data, token): """This function is used by 'qwebactionmanager.js' in order to trigger the download of a pdf/controller report. :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = json.loads(data) url, type = requestcontent[0], requestcontent[1] 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)) cr, uid = request.cr, request.uid report = request.registry['report']._get_report_from_name(cr, uid, reportname) filename = "%s.%s" % (report.name, "pdf") if docids: ids = [int(x) for x in docids.split(",")] obj = request.env[report.model].browse(ids) if report.print_report_name and not len(obj) > 1: filename = eval(report.print_report_name, {'object': obj, 'time': time}) response.headers.add('Content-Disposition', content_disposition(filename)) 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 else: return except Exception, e: se = _serialize_exception(e) error = { 'code': 200, 'message': "Odoo Server Error", 'data': se } return request.make_response(html_escape(json.dumps(error)))
def report(self, output_format, report_name, token, report_id=None, **kw): uid = request.session.uid domain = [('create_uid', '=', uid)] report_model = request.env[ 'account.report.context.common'].get_full_report_name_by_report_name( report_name) report_obj = request.env[report_model].sudo(uid) if report_name == 'financial_report': report_id = int(report_id) domain.append(('report_id', '=', report_id)) report_obj = report_obj.browse(report_id) context_obj = request.env[ 'account.report.context.common'].get_context_by_report_name( report_name) context_id = context_obj.sudo(uid).search(domain, limit=1) try: if output_format == 'xls': response = request.make_response( None, headers=[('Content-Type', 'application/vnd.ms-excel'), ('Content-Disposition', 'attachment; filename=' + report_obj.get_name() + '.xls;')]) context_id.get_xls(response) response.set_cookie('fileToken', token) return response if output_format == 'pdf': response = request.make_response( context_id.get_pdf(), headers=[('Content-Type', 'application/pdf'), ('Content-Disposition', 'attachment; filename=' + report_obj.get_name() + '.pdf;')]) response.set_cookie('fileToken', token) return response if output_format == 'xml': content = context_id.get_xml() response = request.make_response( content, headers=[('Content-Type', 'application/vnd.sun.xml.writer'), ('Content-Disposition', 'attachment; filename=' + report_obj.get_name() + '.xml;'), ('Content-Length', len(content))]) response.set_cookie('fileToken', token) return response except Exception, e: se = _serialize_exception(e) error = {'code': 200, 'message': 'Odoo Server Error', 'data': se} return request.make_response(html_escape(json.dumps(error)))
def report_download(self, data, token): """This function is used by 'qwebactionmanager.js' in order to trigger the download of a pdf/controller report. :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = json.loads(data) url, type = requestcontent[0], requestcontent[1] 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)) cr, uid = request.cr, request.uid report = request.registry["report"]._get_report_from_name(cr, uid, reportname) filename = "%s.%s" % (report.name, "pdf") response.headers.add("Content-Disposition", content_disposition(filename)) 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 else: return except Exception, e: se = _serialize_exception(e) error = {"code": 200, "message": "Odoo Server Error", "data": se} return request.make_response(html_escape(json.dumps(error)))
def report_download(self, data, token): """This function is used by 'qwebactionmanager.js' in order to trigger the download of a pdf/controller report. :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = simplejson.loads(data) url, type = requestcontent[0], requestcontent[1] 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 else: return except osv.except_osv, e: se = _serialize_exception(e) error = { 'code': 200, 'message': "Odoo Server Error", 'data': se } return request.make_response(simplejson.dumps(error))
def followup(self, partners, token, **kw): uid = request.session.uid try: context_obj = request.env['account.report.context.followup'] partners = request.env['res.partner'].browse( [int(i) for i in partners.split(',')]) context_ids = context_obj.search([('partner_id', 'in', partners.ids), ('create_uid', '=', uid)]) response = request.make_response( context_ids.with_context(public=True).get_pdf(log=True), headers=[('Content-Type', 'application/pdf'), ('Content-Disposition', 'attachment; filename=payment_reminder.pdf;')]) response.set_cookie('fileToken', token) return response except Exception, e: se = _serialize_exception(e) error = {'code': 200, 'message': 'Odoo Server Error', 'data': se} return request.make_response(html_escape(json.dumps(error)))
def report_download(self, data, token): """This function is used by 'qwebactionmanager.js' in order to trigger the download of a py3o/controller report. :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = json.loads(data) url, type = requestcontent[0], requestcontent[1] if type != 'py3o': return super(ReportController, self).report_download(data, token) try: reportname = url.split('/report/py3o/')[1].split('?')[0] docids = None if '/' in reportname: reportname, docids = reportname.split('/') if docids: # Generic report: response = self.report_routes(reportname, docids=docids, converter='py3o') print "response", response else: # Particular report: # decoding the args represented in JSON data = url_decode(url.split('?')[1]).items() response = self.report_routes(reportname, converter='py3o', **dict(data)) response.set_cookie('fileToken', token) return response except Exception, e: se = _serialize_exception(e) error = {'code': 200, 'message': "Odoo Server Error", 'data': se} return request.make_response(html_escape(json.dumps(error)))
def esl_download(self, id): try: ESLWizard = request.registry['account.vat.esl'] esl = ESLWizard.browse(request.cr, request.uid, int(id)) if esl: filecontent = esl.esl_csv_data() period_name = esl.period_from.name filename = 'esl_%s.csv' % (period_name,) return request.make_response( filecontent, headers=[ ('Content-Type', 'text/csv'), ('Content-Disposition', content_disposition(filename)), ], ) else: return request.not_found() except Exception, e: error = { 'code': 200, 'message': 'Odoo Server Error', 'data': _serialize_exception(e), } return request.make_response(html_escape(simplejson.dumps(error)))
def report_download(self, data, token): """Hook to change file name, using employee/partner name and resume format """ requestcontent = simplejson.loads(data) url, type = requestcontent[0], requestcontent[1] 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)) # ----- Hook to rename file ------- model = request.registry['ir.actions.report.xml'].search_read( request.cr, request.uid, [('report_name', '=', reportname)], ['model', 'report_file'], context=request.context) model_name = model and model[0]['model'] model_obj = request.registry[model_name] # If model prepared to hook report filename, get filename to use if hasattr(model_obj, 'get_report_filename'): # Set specific filename record_ids = [int(id) for id in docids.split(",")] reportfile_prefix = model[0]['report_file'] report_file = model_obj.get_report_filename( request.cr, request.uid, record_ids, reportfile_prefix, context=request.context) reportname = report_file or reportfile_prefix # ----- End -------------------------- 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 else: return except Exception, e: se = _serialize_exception(e) error = {'code': 200, 'message': "Odoo Server Error", 'data': se} return request.make_response(html_escape(simplejson.dumps(error)))
def report_download(self, data, token): """This function is used by 'report_xls.js' in order to trigger the download of xls/ods report. :param token: token received by controller :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = json.loads(data) url, report_type = requestcontent[0], requestcontent[1] try: if report_type == 'qweb-xls': reportname = url.split('/reportxlstemplate/xls/')[1].split( '?')[0] docids = None if '/' in reportname: reportname, docids = reportname.split('/') if docids: # Generic report: response = self.report_routes(reportname, docids=docids, converter='xls') else: # Particular report: # Decoding the args represented in JSON data = url_decode(url.split('?')[1]).items() response = self.report_routes(reportname, converter='xls', **dict(data)) cr, uid = request.cr, request.uid report = request.registry['report']._get_xls_report_from_name( cr, uid, reportname) filename = "%s.%s" % (report.name, "xlsx") response.headers.add('Content-Disposition', content_disposition(filename)) response.set_cookie('fileToken', token) return response elif report_type == 'qweb-ods': reportname = url.split('/reportxlstemplate/ods/')[1].split( '?')[0] docids = None if '/' in reportname: reportname, docids = reportname.split('/') if docids: # Generic report: response = self.report_routes(reportname, docids=docids, converter='ods') else: # Particular report: # Decoding the args represented in JSON data = url_decode(url.split('?')[1]).items() response = self.report_routes(reportname, converter='ods', **dict(data)) cr, uid = request.cr, request.uid report = request.registry['report']._get_xls_report_from_name( cr, uid, reportname) filename = "%s.%s" % (report.name, "ods") response.headers.add('Content-Disposition', content_disposition(filename)) response.set_cookie('fileToken', token) return response else: return except Exception, e: se = _serialize_exception(e) error = {'code': 200, 'message': "Odoo Server Error", 'data': se} return request.make_response(html_escape(json.dumps(error)))
def report_download(self, data, token): """This function is used by 'report_xls.js' in order to trigger the download of xls/ods report. :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = simplejson.loads(data) url, report_type = requestcontent[0], requestcontent[1] try: if report_type == 'qweb-xls': reportname = url.split('/reportxlstemplate/xls/')[1].split( '?')[0] docids = None if '/' in reportname: reportname, docids = reportname.split('/') if docids: # Generic report: response = self.report_routes(reportname, docids=docids, converter='xls') else: # Particular report: # Decoding the args represented in JSON data = url_decode(url.split('?')[1]).items() response = self.report_routes(reportname, converter='xls', **dict(data)) response.headers.add( 'Content-Disposition', 'attachment; filename=%s.xls;' % reportname) response.set_cookie('fileToken', token) return response elif report_type == 'qweb-ods': reportname = url.split('/reportxlstemplate/ods/')[1].split( '?')[0] docids = None if '/' in reportname: reportname, docids = reportname.split('/') if docids: # Generic report: response = self.report_routes(reportname, docids=docids, converter='ods') else: # Particular report: # Decoding the args represented in JSON data = url_decode(url.split('?')[1]).items() response = self.report_routes(reportname, converter='ods', **dict(data)) response.headers.add( 'Content-Disposition', 'attachment; filename=%s.ods;' % reportname) response.set_cookie('fileToken', token) return response else: return except osv.except_osv, e: se = _serialize_exception(e) error = {'code': 200, 'message': "Odoo Server Error", 'data': se} return request.make_response(simplejson.dumps(error))
def report_download(self, data, token): """This function is used by 'qwebactionmanager.js' in order to trigger the download of a pdf/controller report. :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = simplejson.loads(data) url, type = requestcontent[0], requestcontent[1] 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)) #################### TO CHANGE NAME OF THE QWEB REPORT PDF FILE ################## if docids: if reportname == "account.report_invoice": inv_obj = request.registry['account.invoice'] lst_inv = [] lst_inv = docids.split(",") for ele_inv in lst_inv: inv_browse = inv_obj.browse(request.cr, request.uid, [int(ele_inv)]) if inv_browse[0].type == 'out_invoice' or inv_browse[0].type == 'in_invoice': if inv_browse[0].number: reportname = 'Invoice' + '(' + str(inv_browse[0].number or '') + ')' else: reportname = 'Invoice' else: if inv_browse[0].number: reportname = "Refund" + '(' + str(inv_browse[0].number or '') + ')' else: reportname = 'Refund' if reportname == "sale.report_saleorder": sale_obj = request.registry['sale.order'] lst = [] lst = docids.split(",") for ele in lst: sale_browse = sale_obj.browse(request.cr, request.uid, [int(ele)]) if sale_browse[0].state in ['draft', 'sent']: if sale_browse[0].name: reportname = "Quotation" + '(' + str(sale_browse[0].name) + ')' else: reportname = "Quotation" else : if sale_browse[0].name: reportname = "Order" + '(' + str(sale_browse[0].name) + ')' else: reportname = "Order" if reportname == "purchase.report_purchaseorder": purchase_obj = request.registry['purchase.order'] lst = [] lst = docids.split(",") for ele in lst: purchase_browse = purchase_obj.browse(request.cr, request.uid, [int(ele)]) if purchase_browse[0].state in ['draft', 'sent']: if purchase_browse[0].name: reportname = "Purchase Order" + '(' + str(purchase_browse[0].name) + ')' else: reportname = "Purchase Order" else : if purchase_browse[0].name: reportname = "Purchase Order" + '(' + str(purchase_browse[0].name) + ')' else: reportname = "Purchase Order" #################################################################################### 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 else: return except Exception, e: se = _serialize_exception(e) error = { 'code': 200, 'message': "Odoo Server Error", 'data': se } return request.make_response(html_escape(simplejson.dumps(error)))
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)) #_logger.warning("reportname-2 : %s", reportname ) 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 else: return except Exception, e: se = _serialize_exception(e) error = {'code': 200, 'message': "Odoo Server Error", 'data': se} return request.make_response(html_escape(simplejson.dumps(error)))
def report_download(self, data, token): """This function is used by 'qwebactionmanager.js' in order to trigger the download of a pdf/controller report. :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = simplejson.loads(data) url, type = requestcontent[0], requestcontent[1] 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') ##### FIX START: switch reportname with the evaluated attachment attribute of the action if available docids = [int(i) for i in docids.split(',')] report_obj = request.registry['report'] cr, uid, context = request.cr, request.uid, request.context report = report_obj._get_report_from_name( cr, uid, reportname) if report.attachment: obj = report_obj.pool[report.model].browse( cr, uid, docids[0]) reportname = eval(report.attachment, { 'object': obj }).split('.pdf')[0] ##### FIX END 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 else: return except osv.except_osv, e: se = _serialize_exception(e) error = {'code': 200, 'message': "Odoo Server Error", 'data': se} return request.make_response(simplejson.dumps(error))
def report_download(self, data, token): """This function is used by 'qwebactionmanager.js' in order to trigger the download of a py3o/controller report, and convert report from ods to xlsx with libreoffice :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ response = super(ReportController, self).report_download(data, token) requestcontent = json.loads(data) url, type = requestcontent[0], requestcontent[1] if type != 'py3o': return super(ReportController, self).report_download(data, token) try: reportname = url.split('/report/py3o/')[1].split('?')[0] if '/' in reportname: reportname, docids = reportname.split('/') ir_action = request.env['ir.actions.report.xml'] action_py3o_report = ir_action.get_from_report_name( reportname, "py3o").with_context(request.env.context) outputfile = action_py3o_report.py3o_filetype doutputfile = '.' + outputfile tdoutfile = 'x.' + outputfile if not action_py3o_report.py3o_filetype_template: rftype = action_py3o_report.py3o_template_id.filetype else: rftype = action_py3o_report.py3o_filetype_template ftype = '.' + rftype with open( os.path.dirname(__file__) + '/' + reportname + ftype, 'a+') as create_ods: create_ods.write(response.data) os.system("unoconv -f " + outputfile + " '" + os.path.dirname(__file__) + "/" + reportname + ftype + "'") with open( os.path.dirname(__file__) + '/' + reportname + doutputfile, 'r+') as create_xlsx: res = create_xlsx.read() os.remove(os.path.dirname(__file__) + '/' + reportname + ftype) os.remove( os.path.dirname(__file__) + '/' + reportname + doutputfile) filename = action_py3o_report.gen_report_download_filename( docids, data) filename_without_type = filename.split('.')[0] content_type = mimetypes.guess_type(tdoutfile)[0] http_headers = [ ('Content-Type', content_type), ('Content-Length', len(res)), ('Content-Disposition', content_disposition(filename_without_type + doutputfile)) ] response = request.make_response(res, headers=http_headers) response.set_cookie('fileToken', token) return response except Exception as e: se = _serialize_exception(e) error = {'code': 200, 'message': "Odoo Server Error", 'data': se} return request.make_response(html_escape(json.dumps(error)))
def report_download(self, data, token): """This function is used by 'qwebactionmanager.js' in order to trigger the download of a pdf/controller report. :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = simplejson.loads(data) url, type = requestcontent[0], requestcontent[1] 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)) if reportname == 'jjuice_fedex.report_print_label': cr, context = request.cr, request.context info = request.registry('create.shipment.fedex').read( cr, SUPERUSER_ID, int(docids), ['to_person_name', 'tracking_number']) str_list = [] str_list.append(time.strftime("%Y-%m-%d")) str_list.append( info.get('to_person_name', 'unavailable') or 'unavailable') str_list.append( info.get('tracking_number', 'unavailable') or 'unavailable') label_name = '_'.join(str_list) response.headers.add( 'Content-Disposition', 'attachment; filename=%s.pdf;' % label_name) else: 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 else: return except Exception, e: se = _serialize_exception(e) error = {'code': 200, 'message': "Odoo Server Error", 'data': se} return request.make_response(html_escape(simplejson.dumps(error)))
# Replace all runs of whitespace with a single dash reportname = re.sub(r"\s+", '-', reportname) #_logger.warning("reportname-1 : %s", reportname ) 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)) #_logger.warning("reportname-2 : %s", reportname ) 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 else: return except Exception, e: se = _serialize_exception(e) error = { 'code': 200, 'message': "Odoo Server Error", 'data': se } return request.make_response(html_escape(simplejson.dumps(error)))
def report_download(self, data, token): """This function is used by 'qwebactionmanager.js' in order to trigger the download of a pdf/controller report. :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = simplejson.loads(data) url, type = requestcontent[0], requestcontent[1] try: if type == 'qweb-pdf': reportname = url.split('/report/pdf/')[1].split('?')[0] docids = None if '/' in reportname: reportname, docids = reportname.split('/') print docids, reportname 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)) #Rename the pdf's name make it looks kindly. report_ids = request.registry.get( 'ir.actions.report.xml').search( request.cr, openerp.SUPERUSER_ID, [('report_name', '=', reportname)]) if len(report_ids): report_obj = request.registry.get( 'ir.actions.report.xml').browse( request.cr, openerp.SUPERUSER_ID, report_ids[0]) docids = [int(x) for x in docids.split(',')] reports = request.registry.get(report_obj.model).browse( request.cr, openerp.SUPERUSER_ID, docids) filename = reports[0].name response.headers.add('Content-Disposition', 'attachment; filename=%s.pdf;' % filename) 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 else: return except Exception, e: se = _serialize_exception(e) error = {'code': 200, 'message': "Odoo Server Error", 'data': se} return request.make_response(html_escape(simplejson.dumps(error)))
def report_download(self, data, token): """This function is used by 'qwebactionmanager.js' in order to trigger the download of a pdf/controller report. :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = simplejson.loads(data) url, type = requestcontent[0], requestcontent[1] 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') #switch reportname with the evaluated attachment attribute of the action if available docids = [int(i) for i in docids.split(',')] report_obj = request.registry['report'] cr, uid, context = request.cr, request.uid, request.context report = report_obj._get_report_from_name( cr, uid, reportname) report_ename = "%s_" % (report.name) obj = report_obj.pool[report.model].browse( cr, uid, docids[0]) if len(docids ) > 1: # if more than one reports for printing prefex = "(time.strftime('%d/%m/%Y')) + ('.pdf')" else: prefex_name = "" try: if obj.name: prefex_name = "(object.name)+'_'" except: pass prefex_state = "" try: if obj.state: prefex_state = "'_'+(object.state)+'_'" except: pass prefex = prefex_name + prefex_state + " + (time.strftime('%d/%m/%Y')) + ('.pdf')" #_logger.warning("prefex : %s", prefex ) try: reportname = eval(prefex, { 'object': obj, 'time': time }).split('.pdf')[0] except: pass reportname = report_ename reportname = report_ename + reportname # Remove all non-word characters (everything except numbers and letters) reportname = re.sub(r"[^\w\s]", '', reportname) # Replace all runs of whitespace with a single dash reportname = re.sub(r"\s+", '-', reportname) #_logger.warning("reportname-1 : %s", reportname ) 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)) #_logger.warning("reportname-2 : %s", reportname ) 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 else: return except Exception, e: se = _serialize_exception(e) error = {'code': 200, 'message': "Odoo Server Error", 'data': se} return request.make_response(html_escape(simplejson.dumps(error)))
def report_download(self, data, token): """This function is used by 'qwebactionmanager.js' in order to trigger the download of a pdf/controller report. :param data: a javascript array JSON.stringified containg report internal url ([0]) and type [1] :returns: Response with a filetoken cookie and an attachment header """ requestcontent = simplejson.loads(data) url, type = requestcontent[0], requestcontent[1] 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') #switch reportname with the evaluated attachment attribute of the action if available docids = [int(i) for i in docids.split(',')] report_obj = request.registry['report'] cr, uid, context = request.cr, request.uid, request.context report = report_obj._get_report_from_name(cr, uid, reportname) report_ename = "%s_" % (report.name) obj = report_obj.pool[report.model].browse(cr, uid, docids[0]) if len(docids) > 1: # if more than one reports for printing prefex = "(time.strftime('%d/%m/%Y')) + ('.pdf')" else: prefex_name = "" try: if obj.name: prefex_name = "(object.name)+'_'" except: pass prefex_state = "" try: if obj.state: prefex_state = "'_'+(object.state)+'_'" except: pass prefex = prefex_name + prefex_state + " + (time.strftime('%d/%m/%Y')) + ('.pdf')" #_logger.warning("prefex : %s", prefex ) try: reportname = eval(prefex, {'object': obj, 'time': time}).split('.pdf')[0] except: pass reportname = report_ename reportname = report_ename+reportname # Remove all non-word characters (everything except numbers and letters) reportname = re.sub(r"[^\w\s]", '', reportname) # Replace all runs of whitespace with a single dash reportname = re.sub(r"\s+", '-', reportname) #_logger.warning("reportname-1 : %s", reportname ) 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)) #_logger.warning("reportname-2 : %s", reportname ) 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 else: return except Exception, e: se = _serialize_exception(e) error = { 'code': 200, 'message': "Odoo Server Error", 'data': se } return request.make_response(html_escape(simplejson.dumps(error)))