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.

39 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(
  8. selection_add=[("xlsx", "XLSX")], ondelete={"xlsx": "set default"}
  9. )
  10. @api.model
  11. def _render_xlsx(self, docids, data):
  12. report_model_name = "report.%s" % self.report_name
  13. report_model = self.env.get(report_model_name)
  14. if report_model is None:
  15. raise UserError(_("%s model was not found") % report_model_name)
  16. return report_model.with_context(
  17. active_model=self.model
  18. ).create_xlsx_report( # noqa
  19. docids, data
  20. )
  21. @api.model
  22. def _get_report_from_name(self, report_name):
  23. res = super(ReportAction, self)._get_report_from_name(report_name)
  24. if res:
  25. return res
  26. report_obj = self.env["ir.actions.report"]
  27. qwebtypes = ["xlsx"]
  28. conditions = [
  29. ("report_type", "in", qwebtypes),
  30. ("report_name", "=", report_name),
  31. ]
  32. context = self.env["res.users"].context_get()
  33. return report_obj.with_context(context).search(conditions, limit=1)