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.

38 lines
1.5 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. if result.status_code != 200:
  14. # In case of error don't change the response.
  15. return result
  16. action = json.loads(action)
  17. context = dict(http.request.context)
  18. context.update(action["context"])
  19. report_xml = http.request.env['ir.actions.report.xml']
  20. reports = report_xml.search([
  21. ('report_name', '=', action['report_name']),
  22. ('download_filename', '!=', False)])
  23. for report in reports:
  24. objects = http.request.session.model(context['active_model'])\
  25. .browse(context['active_ids'])
  26. generated_filename = mail_template.mako_template_env\
  27. .from_string(report.download_filename)\
  28. .render({
  29. 'objects': objects,
  30. 'o': objects[0],
  31. 'object': objects[0],
  32. })
  33. result.headers['Content-Disposition'] = main.content_disposition(
  34. generated_filename)
  35. return result