mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[ADD] report_wkhtmltopdf_param
This commit is contained in:
committed by
Jordi Ballester
parent
fd70d2e34c
commit
cc08c2be97
7
report_wkhtmltopdf_param/models/__init__.py
Normal file
7
report_wkhtmltopdf_param/models/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 Avoin.Systems
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import report_paperformat_parameter
|
||||
from . import report_paperformat
|
||||
from . import report
|
||||
24
report_wkhtmltopdf_param/models/report.py
Normal file
24
report_wkhtmltopdf_param/models/report.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 Avoin.Systems
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from openerp import models
|
||||
|
||||
|
||||
class Report(models.Model):
|
||||
_inherit = 'report'
|
||||
|
||||
def _build_wkhtmltopdf_args(self, paperformat,
|
||||
specific_paperformat_args=None):
|
||||
# noinspection PyUnresolvedReferences,PyProtectedMember
|
||||
command_args = super(Report, self)._build_wkhtmltopdf_args(
|
||||
paperformat,
|
||||
specific_paperformat_args
|
||||
)
|
||||
|
||||
for param in paperformat.custom_params:
|
||||
command_args.extend([param.name])
|
||||
if param.value:
|
||||
command_args.extend([param.value])
|
||||
|
||||
return command_args
|
||||
38
report_wkhtmltopdf_param/models/report_paperformat.py
Normal file
38
report_wkhtmltopdf_param/models/report_paperformat.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 Avoin.Systems
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from openerp import api, fields, models, _
|
||||
from openerp.exceptions import ValidationError
|
||||
|
||||
|
||||
class Paper(models.Model):
|
||||
_inherit = 'report.paperformat'
|
||||
|
||||
custom_params = fields.One2many(
|
||||
'report.paperformat.parameter',
|
||||
'paperformat_id',
|
||||
'Custom Parameters',
|
||||
help='Custom Parameters passed forward as wkhtmltopdf '
|
||||
'command arguments'
|
||||
)
|
||||
|
||||
@api.constrains('custom_params')
|
||||
def _check_recursion(self):
|
||||
for paperformat in self:
|
||||
sample_html = """
|
||||
<!DOCTYPE html>
|
||||
<html style="height: 0;">
|
||||
<body>
|
||||
<div>
|
||||
<span itemprop="name">Hello World!</span>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
contenthtml = [tuple([1, sample_html])]
|
||||
content = self.env['report']._run_wkhtmltopdf(
|
||||
[], [], contenthtml, False, paperformat, False, False, False)
|
||||
if not content:
|
||||
raise ValidationError(_(
|
||||
"Failed to create a PDF using the provided parameters."))
|
||||
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 Avoin.Systems
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from openerp import models, fields
|
||||
|
||||
|
||||
class ReportPaperformatParameter(models.Model):
|
||||
_name = 'report.paperformat.parameter'
|
||||
_description = 'wkhtmltopdf parameters'
|
||||
|
||||
paperformat_id = fields.Many2one(
|
||||
'report.paperformat',
|
||||
'Paper Format',
|
||||
required=True,
|
||||
)
|
||||
|
||||
name = fields.Char(
|
||||
'Name',
|
||||
required=True,
|
||||
help='The command argument name. Remember to add prefix -- or -'
|
||||
)
|
||||
|
||||
value = fields.Char(
|
||||
'Value',
|
||||
)
|
||||
Reference in New Issue
Block a user