diff --git a/base_report_assembler/ir_report.py b/base_report_assembler/ir_report.py index 95504350..d1078642 100644 --- a/base_report_assembler/ir_report.py +++ b/base_report_assembler/ir_report.py @@ -94,8 +94,8 @@ class ReportAssembleXML(orm.Model): for rep in self.browse(cr, uid, ids, context=context): if rep.report_type != 'assemblage': continue - if (vals.get('report_name', False) - and vals['report_name'] != rep.report_name): + if (vals.get('report_name', False) and + vals['report_name'] != rep.report_name): report_name = vals['report_name'] else: report_name = rep.report_name diff --git a/report_custom_filename/controllers/reports.py b/report_custom_filename/controllers/reports.py index b092d9ec..d7280daa 100644 --- a/report_custom_filename/controllers/reports.py +++ b/report_custom_filename/controllers/reports.py @@ -21,7 +21,6 @@ import simplejson 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): @@ -33,22 +32,9 @@ class Reports(main.Reports): context = dict(req.context) context.update(action["context"]) 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.read(report_ids, - fields=['download_filename']): - if not report.get('download_filename'): - continue - objects = req.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], - }) + generated_filename = report_xml.generate_filename( + action['report_name'], context) + if generated_filename: result.headers['Content-Disposition'] = main.content_disposition( 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 3d1f5a9e..c7614b55 100644 --- a/report_custom_filename/model/ir_actions_report_xml.py +++ b/report_custom_filename/model/ir_actions_report_xml.py @@ -19,6 +19,7 @@ # ############################################################################## from openerp.osv import fields, orm +from openerp.addons.email_template.email_template import mako_template_env class IrActionsReportXml(orm.Model): @@ -35,3 +36,19 @@ class IrActionsReportXml(orm.Model): 'a report being printed for multiple records or not. You also ' 'have access to `o`, which is the first record in the list') } + + def generate_filename(self, cr, uid, report_name, context=None): + report_ids = self.search( + cr, uid, [('report_name', '=', report_name), + ('download_filename', '!=', False)], + limit=1, context=context) + for report in self.browse(cr, uid, report_ids, context=context): + objects = self.pool[context['active_model']].browse( + cr, uid, context['active_ids'], context=context) + return mako_template_env.from_string( + report.download_filename).render({ + 'objects': objects, + 'o': objects[0], + 'object': objects[0], + }) + return False