From db108e4e0b53370d8ca76eaa73dbd89a6c3a3cd3 Mon Sep 17 00:00:00 2001 From: Sebastien LANGE Date: Tue, 10 May 2016 17:35:33 +0200 Subject: [PATCH] [IMP] Migrate report_custom_filename module to v9 and use download_filename like attachement --- report_custom_filename/__openerp__.py | 5 +- .../controllers/__init__.py | 1 - .../controllers/report_controller.py | 15 ++---- report_custom_filename/controllers/reports.py | 53 ------------------- 4 files changed, 7 insertions(+), 67 deletions(-) delete mode 100644 report_custom_filename/controllers/reports.py diff --git a/report_custom_filename/__openerp__.py b/report_custom_filename/__openerp__.py index 1b78fd7e..de87e23c 100644 --- a/report_custom_filename/__openerp__.py +++ b/report_custom_filename/__openerp__.py @@ -21,14 +21,13 @@ { "name": "Custom report filenames", "summary": "Configure the filename to use when downloading a report", - "version": "8.0.1.0.0", + "version": "9.0.1.0.0", "author": "Therp BV,Odoo Community Association (OCA)", "license": "AGPL-3", "complexity": "normal", "category": "Reporting", "depends": [ 'web', - 'email_template', ], "data": [ "view/ir_actions_report_xml.xml", @@ -36,7 +35,7 @@ "test": [ ], "auto_install": False, - 'installable': False, + 'installable': True, "application": False, "external_dependencies": { 'python': ['jinja2'], diff --git a/report_custom_filename/controllers/__init__.py b/report_custom_filename/controllers/__init__.py index 6eb84a90..a3f2a215 100644 --- a/report_custom_filename/controllers/__init__.py +++ b/report_custom_filename/controllers/__init__.py @@ -18,5 +18,4 @@ # along with this program. If not, see . # ############################################################################## -from . import reports from . import report_controller diff --git a/report_custom_filename/controllers/report_controller.py b/report_custom_filename/controllers/report_controller.py index 536d2d69..409654fd 100644 --- a/report_custom_filename/controllers/report_controller.py +++ b/report_custom_filename/controllers/report_controller.py @@ -19,9 +19,10 @@ # ############################################################################## from openerp import http -from openerp.addons.email_template import email_template from openerp.addons.report.controllers.main import ReportController from openerp.addons.web.controllers.main import content_disposition +from openerp.tools.safe_eval import safe_eval +import time class ReportController(ReportController): @@ -38,18 +39,12 @@ class ReportController(ReportController): report_ids = report_xml.search( [('report_name', '=', reportname)]) for report in report_xml.browse(report_ids): - if not report.download_filename: + if not report.download_filename or len(docids) != 1: continue objects = http.request.session.model(report.model)\ .browse(docids or []) - generated_filename = email_template.mako_template_env\ - .from_string(report.download_filename)\ - .render({ - 'objects': objects, - 'o': objects[:1], - 'object': objects[:1], - 'ext': report.report_type.replace('qweb-', ''), - }) + generated_filename = safe_eval(report.download_filename, + {'object': objects, 'time': time}) response.headers['Content-Disposition'] = content_disposition( generated_filename) return response diff --git a/report_custom_filename/controllers/reports.py b/report_custom_filename/controllers/reports.py deleted file mode 100644 index 1ff58ed0..00000000 --- a/report_custom_filename/controllers/reports.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# This module copyright (C) 2014 Therp BV (). -# -# 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 . -# -############################################################################## -import simplejson -from openerp import http -from openerp.addons.web.controllers import main -from openerp.addons.email_template import email_template - - -class Reports(main.Reports): - @http.route('/web/report', type='http', auth="user") - @main.serialize_exception - def index(self, action, token): - result = super(Reports, self).index(action, token) - action = simplejson.loads(action) - context = dict(http.request.context) - context.update(action["context"]) - report_xml = http.request.session.model('ir.actions.report.xml') - report_ids = report_xml.search( - [('report_name', '=', action['report_name'])], - 0, False, False, context) - for report in report_xml.browse(report_ids): - if not report.download_filename: - continue - objects = http.request.session.model(context['active_model'])\ - .browse(context['active_ids']) - generated_filename = email_template.mako_template_env\ - .from_string(report.download_filename)\ - .render({ - 'objects': objects, - 'o': objects[0], - 'object': objects[0], - }) - result.headers['Content-Disposition'] = main.content_disposition( - generated_filename) - return result