From fcef7b8e41619f83538aac25533ccaf8f16a46c7 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 8 Feb 2018 00:22:15 +0100 Subject: [PATCH] Add support for qweb-txt-csv Thanks to Graeme Gellatly for his suggestion to implement it this way, so that other qweb-txt-* can be easily added with proper filename extension --- report_qweb_txt/models/ir_actions_report_xml.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/report_qweb_txt/models/ir_actions_report_xml.py b/report_qweb_txt/models/ir_actions_report_xml.py index 084d83fd..3f277238 100644 --- a/report_qweb_txt/models/ir_actions_report_xml.py +++ b/report_qweb_txt/models/ir_actions_report_xml.py @@ -8,12 +8,21 @@ from odoo import api, fields, models class IrActionsReportXml(models.Model): _inherit = 'ir.actions.report.xml' - report_type = fields.Selection(selection_add=[('qweb-txt', 'Text')]) + report_type = fields.Selection(selection_add=[ + ('qweb-txt', 'Text'), + ('qweb-txt-csv', 'CSV'), + ]) @api.model def render_report(self, res_ids, name, data): - if data.get('report_type') == 'qweb-txt': - return self.env['report'].get_html(res_ids, name, data=data), 'txt' + if ( + data.get('report_type') and + data.get('report_type').startswith('qweb-txt')): + ext = data['report_type'].split('-')[-1] + # That way, you can easily add qweb-txt-zpl' or others + # without inheriting this method (you just need to do the + # selection_add on the field 'report_type') + return self.env['report'].get_html(res_ids, name, data=data), ext else: return super(IrActionsReportXml, self).render_report( res_ids, name, data)