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.

43 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. from odoo import api, fields, models, _
  5. from odoo.exceptions import ValidationError
  6. import logging
  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 '
  15. 'command arguments'
  16. )
  17. @api.constrains('custom_params')
  18. def _check_recursion(self):
  19. for paperformat in self:
  20. sample_html = """
  21. <!DOCTYPE html>
  22. <html style="height: 0;">
  23. <body>
  24. <div>
  25. <span itemprop="name">Hello World!</span>
  26. </div>
  27. </body>
  28. </html>
  29. """
  30. contenthtml = [bytes(sample_html, 'utf-8')]
  31. report = self.env['ir.actions.report'].new({
  32. 'paperformat_id': paperformat.id
  33. })
  34. content = report._run_wkhtmltopdf(contenthtml)
  35. if not content:
  36. raise ValidationError(_(
  37. "Failed to create a PDF using the provided parameters."))