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.

37 lines
1.3 KiB

  1. # Copyright 2015 ACSONE SA/NV (<http://acsone.eu>)
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  3. from odoo import _, api, fields, models
  4. from odoo.exceptions import UserError
  5. class ReportAction(models.Model):
  6. _inherit = "ir.actions.report"
  7. report_type = fields.Selection(selection_add=[("xlsx", "XLSX")])
  8. @api.model
  9. def render_xlsx(self, docids, data):
  10. report_model_name = "report.%s" % self.report_name
  11. report_model = self.env.get(report_model_name)
  12. if report_model is None:
  13. raise UserError(_("%s model was not found") % report_model_name)
  14. return report_model.with_context(
  15. active_model=self.model
  16. ).create_xlsx_report( # noqa
  17. docids, data
  18. )
  19. @api.model
  20. def _get_report_from_name(self, report_name):
  21. res = super(ReportAction, self)._get_report_from_name(report_name)
  22. if res:
  23. return res
  24. report_obj = self.env["ir.actions.report"]
  25. qwebtypes = ["xlsx"]
  26. conditions = [
  27. ("report_type", "in", qwebtypes),
  28. ("report_name", "=", report_name),
  29. ]
  30. context = self.env["res.users"].context_get()
  31. return report_obj.with_context(context).search(conditions, limit=1)