Browse Source

[IMP] Migrate report_custom_filename module to v9 and use download_filename like attachement

pull/52/head
Sebastien LANGE 9 years ago
parent
commit
db108e4e0b
  1. 5
      report_custom_filename/__openerp__.py
  2. 1
      report_custom_filename/controllers/__init__.py
  3. 15
      report_custom_filename/controllers/report_controller.py
  4. 53
      report_custom_filename/controllers/reports.py

5
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'],

1
report_custom_filename/controllers/__init__.py

@ -18,5 +18,4 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import reports
from . import report_controller

15
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

53
report_custom_filename/controllers/reports.py

@ -1,53 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2014 Therp BV (<http://therp.nl>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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
Loading…
Cancel
Save