OCA reporting engine fork for dev and update.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.4 KiB

8 years ago
8 years ago
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2014 Therp BV (<http://therp.nl>).
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. import json
  5. from openerp import http
  6. from openerp.addons.web.controllers import main
  7. from openerp.addons.mail.models import mail_template
  8. class Reports(main.Reports):
  9. @http.route('/web/report', type='http', auth="user")
  10. @main.serialize_exception
  11. def index(self, action, token):
  12. result = super(Reports, self).index(action, token)
  13. action = json.loads(action)
  14. context = dict(http.request.context)
  15. context.update(action["context"])
  16. report_xml = http.request.env['ir.actions.report.xml']
  17. reports = report_xml.search([
  18. ('report_name', '=', action['report_name']),
  19. ('download_filename', '!=', False)])
  20. for report in reports:
  21. objects = http.request.session.model(context['active_model'])\
  22. .browse(context['active_ids'])
  23. generated_filename = mail_template.mako_template_env\
  24. .from_string(report.download_filename)\
  25. .render({
  26. 'objects': objects,
  27. 'o': objects[0],
  28. 'object': objects[0],
  29. })
  30. result.headers['Content-Disposition'] = main.content_disposition(
  31. generated_filename)
  32. return result