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.

54 lines
2.5 KiB

8 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2014 Therp BV (<http://therp.nl>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp.osv import fields, orm
  22. from openerp.addons.email_template.email_template import mako_template_env
  23. class IrActionsReportXml(orm.Model):
  24. _inherit = 'ir.actions.report.xml'
  25. _columns = {
  26. 'download_filename': fields.char(
  27. 'Download filename',
  28. help='Fill in this field to have a custom file name when '
  29. 'downloading this report. This string is evaluated as a jinja2 '
  30. 'expression.\nYou can use python expressions, `objects` is a '
  31. 'browse record list of the objects for which the report is being '
  32. 'generated.\nCheck for this list\'s length to determine if it is '
  33. 'a report being printed for multiple records or not. You also '
  34. 'have access to `o`, which is the first record in the list')
  35. }
  36. def generate_filename(self, cr, uid, report_name, context=None):
  37. report_ids = self.search(
  38. cr, uid, [('report_name', '=', report_name),
  39. ('download_filename', '!=', False)],
  40. limit=1, context=context)
  41. for report in self.browse(cr, uid, report_ids, context=context):
  42. objects = self.pool[context['active_model']].browse(
  43. cr, uid, context['active_ids'], context=context)
  44. return mako_template_env.from_string(
  45. report.download_filename).render({
  46. 'objects': objects,
  47. 'o': objects[0],
  48. 'object': objects[0],
  49. })
  50. return False