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.

36 lines
1.2 KiB

  1. # Copyright 2019 Creu Blanca
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo.tools.safe_eval import safe_eval
  4. from odoo import api, fields, models
  5. class IrActionsReport(models.Model):
  6. _inherit = 'ir.actions.report'
  7. context = fields.Char(
  8. string='Context Value', default={},
  9. required=True,
  10. help="Context dictionary as Python expression, empty by default "
  11. "(Default: {})")
  12. def _get_context(self):
  13. self.ensure_one()
  14. context = self.env['ir.config_parameter'].sudo().get_param(
  15. 'report.default.context', '{}')
  16. # We must transform it to a dictionary
  17. context = safe_eval(context or '{}')
  18. report_context = safe_eval(self.context or '{}')
  19. context.update(report_context)
  20. context.update(self.env.context)
  21. return context
  22. @api.multi
  23. def render(self, res_ids, data=None):
  24. return super(IrActionsReport, self.with_context(
  25. self._get_context())).render(res_ids, data=data)
  26. @api.noguess
  27. def report_action(self, docids, data=None, config=True):
  28. return super(IrActionsReport, self.with_context(
  29. self._get_context()
  30. )).report_action(docids, data=data, config=config)