mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[ADD] module 'report_wkhtmltopdf_param'
This commit is contained in:
committed by
Maksym Yankin
parent
1af26d64c6
commit
371b9e60d8
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
|
||||
25
report_wkhtmltopdf_param/models/report.py
Normal file
25
report_wkhtmltopdf_param/models/report.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 Avoin.Systems
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services, S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo 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
|
||||
42
report_wkhtmltopdf_param/models/report_paperformat.py
Normal file
42
report_wkhtmltopdf_param/models/report_paperformat.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2017 Avoin.Systems
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services, S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
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 odoo 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