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.

35 lines
1.2 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(active_model=self.model).create_xlsx_report( # noqa
  15. docids, data
  16. )
  17. @api.model
  18. def _get_report_from_name(self, report_name):
  19. res = super(ReportAction, self)._get_report_from_name(report_name)
  20. if res:
  21. return res
  22. report_obj = self.env["ir.actions.report"]
  23. qwebtypes = ["xlsx"]
  24. conditions = [
  25. ("report_type", "in", qwebtypes),
  26. ("report_name", "=", report_name),
  27. ]
  28. context = self.env["res.users"].context_get()
  29. return report_obj.with_context(context).search(conditions, limit=1)