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.

69 lines
2.6 KiB

  1. # © 2013 XCG Consulting <http://odoo.consulting>
  2. # © 2017 Therp BV <http://therp.nl>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import logging
  5. from odoo import _, api, fields, models
  6. from odoo.exceptions import ValidationError
  7. logger = logging.getLogger(__name__)
  8. class IrActionsReport(models.Model):
  9. _inherit = "ir.actions.report"
  10. @api.constrains("py3o_is_local_fusion", "py3o_server_id")
  11. def _check_py3o_server_id(self):
  12. for report in self:
  13. if report.report_type != "py3o":
  14. continue
  15. if not report.py3o_is_local_fusion and not report.py3o_server_id:
  16. raise ValidationError(
  17. _(
  18. "You can not use remote fusion without Fusion server. "
  19. "Please specify a Fusion Server"
  20. )
  21. )
  22. py3o_is_local_fusion = fields.Boolean(
  23. "Local Fusion",
  24. help="Native formats will be processed without a server. "
  25. "You must use this mode if you call methods on your model into "
  26. "the template.",
  27. default=True,
  28. )
  29. py3o_server_id = fields.Many2one("py3o.server", "Fusion Server")
  30. pdf_options_id = fields.Many2one(
  31. "py3o.pdf.options",
  32. string="PDF Options",
  33. ondelete="restrict",
  34. help="PDF options can be set per report, but also per Py3o Server. "
  35. "If both are defined, the options on the report are used.",
  36. )
  37. @api.depends(
  38. "lo_bin_path", "is_py3o_native_format", "report_type", "py3o_server_id"
  39. )
  40. def _compute_py3o_report_not_available(self):
  41. for rec in self:
  42. rec.is_py3o_report_not_available = False
  43. rec.msg_py3o_report_not_available = ""
  44. if not rec.report_type == "py3o":
  45. continue
  46. if (
  47. not rec.is_py3o_native_format
  48. and not rec.lo_bin_path
  49. and not rec.py3o_server_id
  50. ):
  51. rec.is_py3o_report_not_available = True
  52. rec.msg_py3o_report_not_available = (
  53. _(
  54. "A fusion server or a libreoffice runtime are required "
  55. "to genereate the py3o report '%s'. If the libreoffice"
  56. "runtime is already installed and is not found by "
  57. "Odoo, you can provide the full path to the runtime by "
  58. "setting the key 'py3o.conversion_command' into the "
  59. "configuration parameters."
  60. )
  61. % rec.name
  62. )