def report_routes(self, reportname, docids=None, converter=None, **data): _logger.info("Report %s:%s:%s:%s" % (reportname, docids, converter, data)) if converter in ('glabels', 'glabels_raws'): report = request.env['ir.actions.report']._get_report_from_name( reportname) context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(',')] if data.get('options'): data.update(json.loads(data.pop('options'))) if data.get('context'): # 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'] = json.loads(data['context']) if data['context'].get('lang'): del data['context']['lang'] context.update(data['context']) if converter == 'glabels': pdf = report.with_context(context).render_glabels(docids, data=data)[0] elif converter == 'glabels_raws': pdf = report.with_context(context).render_glabels_raws( docids, data=data)[0] pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf)), ('Content-Disposition', 'attachment; filename=' + reportname + '.pdf')] #_logger.info("Pdf %s" % pdf) return request.make_response(pdf, headers=pdfhttpheaders) return super(ReportController, self).report_routes(reportname, docids, converter, **data)
def report_routes(self, reportname, docids=None, converter=None, **data): if converter not in ['xlsx', 'txt', 'zip']: return super(ReportController, self).report_routes( reportname, docids, converter, **data ) report = request.env['ir.actions.report']._get_report_from_name(reportname) context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(',')] if data.get('options'): data.update(json.loads(data.pop('options'))) if data.get('context'): data['context'] = json.loads(data['context']) if data['context'].get('lang'): del data['context']['lang'] context.update(data['context']) if converter == 'xlsx': body = report.with_context(context).render_xlsx( docids, data=data )[0] bodyhttpheaders = [ ('Content-Type', 'application/vnd.openxmlformats-' 'officedocument.spreadsheetml.sheet'), ('Content-Length', len(body)), ( 'Content-Disposition', content_disposition(report.report_file + '.xlsx') ) ] elif converter == 'txt': report_name = report.render_txt_name(docids, data=data) or '%s.txt'%( report.report_file ) body = report.with_context(context).render_txt( docids, data=data )[0] bodyhttpheaders = [ ('Content-Type', 'text/plain'), ('Content-Length', len(body)), ( 'Content-Disposition', content_disposition( report_name ) ) ] elif converter == 'zip': body = report.with_context(context).render_zip( docids, data=data )[0] bodyhttpheaders = [ ('Content-Type', 'application/octet-stream'), ('Content-Length', len(body)), ( 'Content-Disposition', content_disposition(report.report_file + '.zip') ) ] return request.make_response(body, headers=bodyhttpheaders) """
def report_routes(self, reportname, docids=None, converter=None, **data): if converter == 'docx': report = request.env['ir.actions.report']._get_report_from_name( reportname) context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(',')] if data.get('options'): data.update(json.loads(data.pop('options'))) if data.get('context'): # 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'] = json.loads(data['context']) if data['context'].get('lang'): del data['context']['lang'] context.update(data['context']) docx = report.with_context(context).render_docx(docids, data=data)[0] docxhttpheaders = [ ('Content-Type', 'application/vnd.openxmlformats-' 'officedocument.wordprocessingml.document'), ('Content-Length', len(docx)), ('Content-Disposition', content_disposition(report.report_file + '.docx')) ] return request.make_response(docx, headers=docxhttpheaders) return super(ReportController, self).report_routes(reportname, docids, converter, **data)
def report_routes(self, reportname, docids=None, converter=None, **data): if converter == 'xml': report = request.env['ir.actions.report']._get_report_from_name( reportname) context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(',')] if data.get('options'): data.update(json.loads(data.pop('options'))) if data.get('context'): # 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'] = json.loads(data['context']) if data['context'].get('lang'): del data['context']['lang'] context.update(data['context']) xml = report.with_context(context).render_qweb_xml(docids, data=data)[0] xmlhttpheaders = [('Content-Type', 'text/xml'), ('Content-Length', len(xml))] return request.make_response(xml, headers=xmlhttpheaders) else: return super(ReportController, self).report_routes(reportname, docids, converter, **data)
def report_routes(self, reportname, docids=None, converter=None, **data): if converter == "xlsx": report = request.env["ir.actions.report"]._get_report_from_name( reportname) context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(",")] if data.get("options"): data.update(json.loads(data.pop("options"))) if data.get("context"): # 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"] = json.loads(data["context"]) if data["context"].get("lang"): del data["context"]["lang"] context.update(data["context"]) xlsx = report.with_context(context).render_xlsx(docids, data=data)[0] report_name = report.report_file if report.print_report_name: report_name = report.print_report_name xlsxhttpheaders = [ ( "Content-Type", "application/vnd.openxmlformats-" "officedocument.spreadsheetml.sheet", ), ("Content-Length", len(xlsx)), ("Content-Disposition", content_disposition(report_name + ".xlsx")), ] return request.make_response(xlsx, headers=xlsxhttpheaders) return super(ReportController, self).report_routes(reportname, docids, converter, **data)
def report_routes(self, reportname, docids=None, converter=None, **data): if converter == "xlsx": report = request.env["ir.actions.report"]._get_report_from_name(reportname) context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(",")] if data.get("options"): data.update(json.loads(data.pop("options"))) if data.get("context"): data["context"] = json.loads(data["context"]) if data["context"].get("lang"): del data["context"]["lang"] context.update(data["context"]) xlsx = report.with_context(context)._render_xlsx(docids, data=data)[0] report_name = report.report_file if report.print_report_name and not len(docids) > 1: obj = request.env[report.model].browse(docids[0]) report_name = safe_eval( report.print_report_name, {"object": obj} ) xlsxhttpheaders = [ ( "Content-Type", "application/vnd.openxmlformats-" "officedocument.spreadsheetml.sheet", ), ("Content-Length", len(xlsx)), ("Content-Disposition", content_disposition(report_name + ".xlsx")), ] return request.make_response(xlsx, headers=xlsxhttpheaders) return super(ReportController, self).report_routes( reportname, docids, converter, **data )
def report_routes(self, reportname, docids=None, converter=None, **data): if converter == 'xlsx': report = request.env['ir.actions.report']._get_report_from_name( reportname) context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(',')] if data.get('options'): data.update(json.loads(data.pop('options'))) if data.get('context'): # 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'] = json.loads(data['context']) if data['context'].get('lang'): del data['context']['lang'] context.update(data['context']) xlsx = report.with_context(context).render_xlsx(docids, data=data)[0] report_name = report.report_file if report.print_report_name and not len(docids) > 1: obj = request.env[report.model].browse(docids[0]) report_name = safe_eval(report.print_report_name, { 'object': obj, 'time': time }) xlsxhttpheaders = [('Content-Type', 'application/vnd.openxmlformats-' 'officedocument.spreadsheetml.sheet'), ('Content-Length', len(xlsx)), ('Content-Disposition', content_disposition(report_name + '.xlsx'))] return request.make_response(xlsx, headers=xlsxhttpheaders) return super(ReportController, self).report_routes(reportname, docids, converter, **data)
def report_routes(self, reportname, docids=None, converter=None, **data): if converter == "jasperserver": report = request.env["ir.actions.report"]._get_report_from_name( reportname) context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(",")] if data.get('options'): data.update(json.loads(data.pop("options"))) if data.get("context"): # 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"] = json.loads(data["context"]) if data["context"].get("lang"): del data["context"]["lang"] context.update(data["context"]) pdf = report.with_context(context).render_jasperserver_pdf( docids, data=data)[0] filename = "{}.{}".format(report.name, "pdf") if report.print_report_name and not len(docids) > 1: obj = request.env[report.model].browse(docids) report_name = safe_eval(report.print_report_name, { "object": obj, "time": time }) filename = "{}.{}".format(report_name, "pdf") pdfhttpheaders = [ ("Content-Type", "application/pdf"), ("Content-Length", len(pdf)), ("Content-Disposition", content_disposition(filename)), ] return request.make_response(pdf, headers=pdfhttpheaders) return super(ReportController, self).report_routes(reportname, docids, converter, **data)
def report_routes(self, reportname, docids=None, converter=None, **data): if converter == "xml": report = request.env["ir.actions.report"]._get_report_from_name( reportname) context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(",")] if data.get("options"): data.update(json.loads(data.pop("options"))) if data.get("context"): # 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"] = json.loads(data["context"]) if data["context"].get("lang"): del data["context"]["lang"] context.update(data["context"]) xml = report.with_context(context)._render_qweb_xml(docids, data=data)[0] xmlhttpheaders = [ ("Content-Type", "text/xml"), ("Content-Length", len(xml)), ] return request.make_response(xml, headers=xmlhttpheaders) else: return super().report_routes(reportname, docids, converter, **data)
def report_routes(self, reportname, docids=None, converter=None, **data): if converter == 'xlsx': report = request.env['ir.actions.report']._get_report_from_name( reportname) context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(',')] if data.get('options'): data.update(json.loads(data.pop('options'))) if data.get('context'): data['context'] = json.loads(data['context']) if data['context'].get('lang'): del data['context']['lang'] context.update(data['context']) xlsx = report.with_context(context).render_xlsx( docids, data=data )[0] xlsxhttpheaders = [ ('Content-Type', 'application/vnd.openxmlformats-' 'officedocument.spreadsheetml.sheet'), ('Content-Length', len(xlsx)), ( 'Content-Disposition', content_disposition(report.report_file + '.xlsx') ) ] return request.make_response(xlsx, headers=xlsxhttpheaders) return super(ReportController, self).report_routes( reportname, docids, converter, **data )
def report_routes(self, reportname, docids=None, converter=None, **data): if converter == 'jasper': report = request.env['ir.actions.report']._get_report_from_name( reportname) context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(',')] if data.get('options'): data.update(json.loads(data.pop('options'))) if data.get('context'): # 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'] = json.loads(data['context']) if data['context'].get('lang'): del data['context']['lang'] context.update(data['context']) file_data = report.with_context(context).render_jasper( docids, data=data)[0] jasperhttpheaders = [ ('Content-Type', _CONTENT_TYPE.get(report.jasper_output)), ('Content-Length', len(file_data)), ('Content-Disposition', 'attachment; filename=%s%s' % ((report.report_file and report.report_file or 'Report'), '.' + report.jasper_output)) ] return request.make_response(file_data, headers=jasperhttpheaders) return super(ReportController, self).report_routes(reportname, docids, converter, **data)
def report_routes(self, reportname, docids=None, converter=None, **data): report = request.env['ir.actions.report']._get_report_from_name( reportname) original_context = json.loads(data.get('context', '{}')) data['context'] = json.dumps( report.with_context(original_context)._get_context()) return super().report_routes(reportname, docids=docids, converter=converter, **data)
def report_routes(self, reportname, docids=None, converter=None, **data): if converter == 'merged': context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(',')] if data.get('options'): data.update(json.loads(data.pop('options'))) if data.get('context'): # 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'] = json.loads(data['context']) if data['context'].get('lang'): del data['context']['lang'] context.update(data['context']) action_report_obj = request.env['ir.actions.report'] report = action_report_obj._get_report_from_name(reportname) merged = report.with_context(context).render_merged(docids, data=data) filename = "%s.%s" % (report.name, merged[1]) mimetype = 'text/html' if merged[1] == 'qweb-html': mimetype = 'text/html' elif merged[1] == 'qweb-pdf': mimetype = 'application/pdf' elif merged[1] in ('csv', 'txt'): mimetype = 'text/plain' if docids: obj = request.env[report.model].browse(docids) if report.print_report_name and not len(obj) > 1: report_name = safe_eval(report.print_report_name, { 'object': obj, 'time': time, 'multi': False }) filename = "%s.%s" % (report_name, merged[1]) # When we print multiple records we still allow a custom # filename. elif report.print_report_name and len(obj) > 1: report_name = safe_eval(report.print_report_name, { 'objects': obj, 'time': time, 'multi': True }) filename = "%s.%s" % (report_name, merged[1]) csvhttpheaders = [('Content-Type', mimetype), ('Content-Length', len(merged[0])), ('Content-Disposition', content_disposition(filename))] return request.make_response(merged[0], headers=csvhttpheaders) return super(ReportController, self).report_routes(reportname, docids, converter, **data)
def report_routes(self, reportname, docids=None, converter=None, **data): report = request.env['ir.actions.report']._get_report_from_name(reportname) context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(',')] if data.get('options'): data.update(json.loads(data.pop('options'))) if data.get('context'): # 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'] = json.loads(data['context']) if data['context'].get('lang'): del data['context']['lang'] context.update(data['context']) #if converter == 'html': # html = report.with_context(context).render_qweb_html(docids, data=data)[0] # return request.make_response(html) #elif converter == 'pdf': # pdf = report.with_context(context).render_qweb_pdf(docids, data=data)[0] # pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))] # return request.make_response(pdf, headers=pdfhttpheaders) if converter == 'xls': xls = report.with_context(context).render_qweb_xls(docids, data=data) xlshttpheaders = [('Content-Type', 'application/excel'), ('Content-Length', len(xls))] return request.make_response(xls, headers=xlshttpheaders) if converter == 'ppt': ppt = report.with_context(context).render_qweb_ppt(docids, data=data) ppthttpheaders = [('Content-Type', 'application/powerpoint'), ('Content-Length', len(ppt))] return request.make_response(ppt, headers=ppthttpheaders) if converter == 'pptp': pdf = report.with_context(context).render_qweb_ppt(docids, data=data) pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))] return request.make_response(pdf, headers=pdfhttpheaders) if converter == 'lbl': pdf = report.with_context(context).render_qweb_lbl(docids, data=data) pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))] return request.make_response(pdf, headers=pdfhttpheaders) return super(ReportController, self).report_routes(reportname, docids, converter, **data)
def report_routes(self, reportname, docids=None, converter=None, **data): if converter == "csv": report = request.env["ir.actions.report"]._get_report_from_name( reportname) context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(",")] if data.get("options"): data.update(json.loads(data.pop("options"))) if data.get("context"): # 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"] = json.loads(data["context"]) if data["context"].get("lang"): del data["context"]["lang"] context.update(data["context"]) csv = report.with_context(context).render_csv(docids, data=data)[0] filename = "{}.{}".format(report.name, "csv") if docids: obj = request.env[report.model].browse(docids) if report.print_report_name and not len(obj) > 1: report_name = safe_eval( report.print_report_name, { "object": obj, "time": time, "multi": False }, ) filename = "{}.{}".format(report_name, "csv") # When we print multiple records we still allow a custom # filename. elif report.print_report_name and len(obj) > 1: report_name = safe_eval( report.print_report_name, { "objects": obj, "time": time, "multi": True }, ) filename = "{}.{}".format(report_name, "csv") csvhttpheaders = [ ("Content-Type", "text/csv"), ("Content-Length", len(csv)), ("Content-Disposition", content_disposition(filename)), ] return request.make_response(csv, headers=csvhttpheaders) return super(ReportController, self).report_routes(reportname, docids, converter, **data)
def _report_routes_xlsx(self, reportname, docids=None, converter=None, **data): try: report = request.env["ir.actions.report"]._get_report_from_name( reportname) context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(",")] if data.get("options"): data.update(json.loads(data.pop("options"))) if data.get("context"): # 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"] = json.loads(data["context"]) if data["context"].get("lang"): del data["context"]["lang"] context.update(data["context"]) if not docids and data["context"].get("active_ids"): docids = data["context"].get("active_ids") xlsx = report.with_context(context)._render_xlsx(docids, data=data)[0] report_name = report.report_file if report.print_report_name and docids and not len(docids) > 1: obj = request.env[report.model].browse(docids[0]) report_name = safe_eval(report.print_report_name, {"object": obj}) xlsxhttpheaders = [ ( "Content-Type", "application/vnd.openxmlformats-" "officedocument.spreadsheetml.sheet", ), ("Content-Length", len(xlsx)), ("Content-Disposition", content_disposition(report_name + ".xlsx")), ] return request.make_response(xlsx, headers=xlsxhttpheaders) 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_routes(self, reportname, docids=None, converter=None, **data): if converter == "excel": report = request.env["ir.actions.report"]._get_report_from_name( reportname) context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(",")] if data.get("options"): data.update(json.loads(data.pop("options"))) if data.get("context"): # 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"] = json.loads(data["context"]) if data["context"].get("lang"): del data["context"]["lang"] context.update(data["context"]) excel, report_name = report.with_context(context).render_excel( docids, data=data) excel = base64.decodestring(excel) if report.print_report_name and not len(docids) > 1: obj = request.env[report.model].browse(docids[0]) file_ext = report_name.split(".")[-1:].pop() report_name = safe_eval(report.print_report_name, { "object": obj, "time": time }) report_name = "{}.{}".format(report_name, file_ext) excelhttpheaders = [ ( "Content-Type", "application/vnd.openxmlformats-" "officedocument.spreadsheetml.sheet", ), ("Content-Length", len(excel)), ("Content-Disposition", content_disposition(report_name)), ] return request.make_response(excel, headers=excelhttpheaders) return super(ReportController, self).report_routes(reportname, docids, converter, **data)
def report_routes(self, reportname, docids=None, converter=None, **data): print('converter', converter) if converter == 'zip': report = request.env['ir.actions.report']._get_report_from_name( reportname) context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(',')] if data.get('options'): data.update(json.loads(data.pop('options'))) zipfile = report.with_context(context).render_zip(docids, data=data)[0] filename = "%s.%s" % (report.name, "zip") if docids: obj = request.env[report.model].browse(docids) if report.print_report_name and not len(obj) > 1: report_name = safe_eval(report.print_report_name, { 'object': obj, 'time': time, 'multi': False }) filename = "%s.%s" % (report_name, "zip") elif report.print_report_name and len(obj) > 1: report_name = safe_eval(report.print_report_name, { 'objects': obj, 'time': time, 'multi': True }) filename = "%s.%s" % (report_name, "zip") ziphttpheaders = [('Content-Type', 'text/zip'), ('Content-Length', len(zipfile)), ('Content-Disposition', content_disposition(filename))] return request.make_response(zipfile, headers=ziphttpheaders) return super(ReportController, self).report_routes(reportname, docids, converter, **data)
def report_routes(self, reportname, docids=None, converter=None, **data): if converter in ('xml', 'xls', 'ppt', 'pptp', 'fillpdf', 'doc', 'docp'): report = request.env['ir.actions.report']._get_report_from_name( reportname) context = dict(request.env.context) if docids: docids = [int(i) for i in docids.split(',')] if data.get('options'): data.update(json.loads(data.pop('options'))) if data.get('context'): # 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'] = json.loads(data['context']) if data['context'].get('lang'): del data['context']['lang'] context.update(data['context']) if converter == 'xml': xml = report.with_context(context).render_qweb_xml( docids, data=data)[0] xmlhttpheaders = [('Content-Type', 'text/xml'), ('Content-Length', len(xml))] return request.make_response(xml, headers=xmlhttpheaders) elif converter == 'xls': xls = report.with_context(context).render_qweb_xls(docids, data=data) xlshttpheaders = [('Content-Type', 'application/excel'), ('Content-Length', len(xls))] return request.make_response(xls, headers=xlshttpheaders) elif converter == 'ppt': ppt = report.with_context(context).render_qweb_ppt(docids, data=data) ppthttpheaders = [('Content-Type', 'application/powerpoint'), ('Content-Length', len(ppt))] return request.make_response(ppt, headers=ppthttpheaders) elif converter == 'pptp': pdf = report.with_context(context).render_qweb_ppt(docids, data=data) pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))] return request.make_response(pdf, headers=pdfhttpheaders) elif converter == 'doc': ppt = report.with_context(context).render_qweb_doc(docids, data=data) ppthttpheaders = [('Content-Type', 'application/word'), ('Content-Length', len(ppt))] return request.make_response(ppt, headers=ppthttpheaders) elif converter == 'docp': pdf = report.with_context(context).render_qweb_doc(docids, data=data) pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))] return request.make_response(pdf, headers=pdfhttpheaders) elif converter == 'fillpdf': pdf = report.with_context(context).render_fillpdf(docids, data=data)[0] pdfhttpheaders = [ ('Content-Type', 'application/pdf'), ('Content-Length', len(pdf)), ('Content-Disposition', content_disposition(report.report_file + '.pdf')) ] return request.make_response(pdf, headers=pdfhttpheaders) else: return super(ReportController, self).report_routes(reportname, docids, converter, **data)