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.

44 lines
1.4 KiB

  1. # Copyright 2017 Avoin.Systems
  2. # Copyright 2017 Eficent Business and IT Consulting Services, S.L.
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  4. import logging
  5. from odoo import _, api, fields, models
  6. from odoo.exceptions import ValidationError
  7. _logger = logging.getLogger(__name__)
  8. class Paper(models.Model):
  9. _inherit = "report.paperformat"
  10. custom_params = fields.One2many(
  11. "report.paperformat.parameter",
  12. "paperformat_id",
  13. "Custom Parameters",
  14. help="Custom Parameters passed forward as wkhtmltopdf command arguments",
  15. )
  16. @api.constrains("custom_params")
  17. def _check_recursion(self):
  18. for paperformat in self:
  19. sample_html = """
  20. <!DOCTYPE html>
  21. <html style="height: 0;">
  22. <body>
  23. <div>
  24. <span itemprop="name">Hello World!</span>
  25. </div>
  26. </body>
  27. </html>
  28. """
  29. contenthtml = [bytes(sample_html, "utf-8")]
  30. report = self.env["ir.actions.report"].new(
  31. {"paperformat_id": paperformat.id}
  32. )
  33. content = report._run_wkhtmltopdf(contenthtml)
  34. if not content:
  35. raise ValidationError(
  36. _("Failed to create a PDF using the provided parameters.")
  37. )