Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
6
report_wkhtmltopdf_param/models/__init__.py
Normal file
6
report_wkhtmltopdf_param/models/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
# Copyright 2017 Avoin.Systems
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import report_paperformat_parameter
|
||||
from . import report_paperformat
|
||||
from . import report
|
||||
29
report_wkhtmltopdf_param/models/report.py
Normal file
29
report_wkhtmltopdf_param/models/report.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# Copyright 2017 Avoin.Systems
|
||||
# Copyright 2017 ForgeFlow, S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class IrActionsReport(models.Model):
|
||||
_inherit = "ir.actions.report"
|
||||
|
||||
@api.model
|
||||
def _build_wkhtmltopdf_args(
|
||||
self,
|
||||
paperformat_id,
|
||||
landscape,
|
||||
specific_paperformat_args=None,
|
||||
set_viewport_size=False,
|
||||
):
|
||||
# noinspection PyUnresolvedReferences,PyProtectedMember
|
||||
command_args = super()._build_wkhtmltopdf_args(
|
||||
paperformat_id, landscape, specific_paperformat_args, set_viewport_size
|
||||
)
|
||||
|
||||
for param in paperformat_id.custom_params:
|
||||
command_args.extend([param.name])
|
||||
if param.value:
|
||||
command_args.extend([param.value])
|
||||
|
||||
return command_args
|
||||
43
report_wkhtmltopdf_param/models/report_paperformat.py
Normal file
43
report_wkhtmltopdf_param/models/report_paperformat.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# Copyright 2017 Avoin.Systems
|
||||
# Copyright 2017 ForgeFlow, S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
import logging
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
_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_custom_params(self):
|
||||
for paperformat in self:
|
||||
sample_html = """
|
||||
<!DOCTYPE html>
|
||||
<html style="height: 0;">
|
||||
<body>
|
||||
<div>
|
||||
<span itemprop="name">Hello World!</span>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
report = self.env["ir.actions.report"].new(
|
||||
{"paperformat_id": paperformat.id}
|
||||
)
|
||||
content = report._run_wkhtmltopdf([sample_html])
|
||||
if not content:
|
||||
raise ValidationError(
|
||||
self.env._("Failed to create a PDF using the provided parameters.")
|
||||
)
|
||||
@@ -0,0 +1,22 @@
|
||||
# Copyright 2017 Avoin.Systems
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ReportPaperformatParameter(models.Model):
|
||||
_name = "report.paperformat.parameter"
|
||||
_description = "wkhtmltopdf parameters"
|
||||
|
||||
paperformat_id = fields.Many2one(
|
||||
"report.paperformat",
|
||||
"Paper Format",
|
||||
required=True,
|
||||
)
|
||||
|
||||
name = fields.Char(
|
||||
required=True,
|
||||
help="The command argument name. Remember to add prefix -- or -",
|
||||
)
|
||||
|
||||
value = fields.Char()
|
||||
Reference in New Issue
Block a user