From 3f8fb0bc3d46f522df18b89a65ebb18713d355dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Fri, 8 May 2015 13:15:42 +0200 Subject: [PATCH] [BACK] backport module to 7 version --- report_custom_filename/controllers/reports.py | 24 +++++++++---------- .../model/ir_actions_report_xml.py | 24 ++++++++++--------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/report_custom_filename/controllers/reports.py b/report_custom_filename/controllers/reports.py index 1ff58ed0..303976db 100644 --- a/report_custom_filename/controllers/reports.py +++ b/report_custom_filename/controllers/reports.py @@ -19,35 +19,35 @@ # ############################################################################## import simplejson -from openerp import http +from openerp.addons.web 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) + + @http.httprequest + def index(self, req, action, token): + result = super(Reports, self).index(req, action, token) action = simplejson.loads(action) - context = dict(http.request.context) + context = dict(req.context) context.update(action["context"]) - report_xml = http.request.session.model('ir.actions.report.xml') + report_xml = req.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: + for report in report_xml.read(report_ids, fields=['download_filename']): + if not report['download_filename']: continue - objects = http.request.session.model(context['active_model'])\ + objects = req.session.model(context['active_model'])\ .browse(context['active_ids']) generated_filename = email_template.mako_template_env\ - .from_string(report.download_filename)\ + .from_string(report['download_filename'])\ .render({ 'objects': objects, 'o': objects[0], 'object': objects[0], }) result.headers['Content-Disposition'] = main.content_disposition( - generated_filename) + generated_filename, req) return result diff --git a/report_custom_filename/model/ir_actions_report_xml.py b/report_custom_filename/model/ir_actions_report_xml.py index 27cd638c..3d1f5a9e 100644 --- a/report_custom_filename/model/ir_actions_report_xml.py +++ b/report_custom_filename/model/ir_actions_report_xml.py @@ -18,18 +18,20 @@ # along with this program. If not, see . # ############################################################################## -from openerp import models, fields +from openerp.osv import fields, orm -class IrActionsReportXml(models.Model): +class IrActionsReportXml(orm.Model): _inherit = 'ir.actions.report.xml' - download_filename = fields.Char( - 'Download filename', - help='Fill in this field to have a custom file name when downloading ' - 'this report. This string is evaluated as a jinja2 expression.\n' - 'You can use python expressions, `objects` is a browse record list of ' - 'the objects for which the report is being generated.\n' - 'Check for this list\'s length to determine if it is a report being ' - 'printed for multiple records or not. You also have access to `o`, ' - 'which is the first record in the list') + _columns = { + 'download_filename': fields.char( + 'Download filename', + help='Fill in this field to have a custom file name when ' + 'downloading this report. This string is evaluated as a jinja2 ' + 'expression.\nYou can use python expressions, `objects` is a ' + 'browse record list of the objects for which the report is being ' + 'generated.\nCheck for this list\'s length to determine if it is ' + 'a report being printed for multiple records or not. You also ' + 'have access to `o`, which is the first record in the list') + }