[ADD] module 'report_wkhtmltopdf_param'

This commit is contained in:
Miku Laitinen
2017-04-26 17:13:13 +02:00
committed by Maksym Yankin
parent 1af26d64c6
commit 371b9e60d8
80 changed files with 7410 additions and 0 deletions

View 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

View 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

View 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."))

View File

@@ -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',
)