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.5 KiB

  1. # Copyright 2019 Ecosoft Co., Ltd (http://ecosoft.co.th/)
  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=[("excel", "Excel")])
  8. @api.model
  9. def render_excel(self, docids, data):
  10. if len(docids) != 1:
  11. raise UserError(
  12. _('Only one id is allowed for excel_import_export'))
  13. xlsx_template = self.env['xlsx.template'].search(
  14. [('fname', '=', self.report_name), ('res_model', '=', self.model)])
  15. if not xlsx_template or len(xlsx_template) != 1:
  16. raise UserError(
  17. _("Template %s on model %s is not unique!" %
  18. (self.report_name, self.model)))
  19. Export = self.env['xlsx.export']
  20. return Export.export_xlsx(xlsx_template, self.model, docids[0])
  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 = ['excel']
  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)