[IMP] report_wkhtmltopdf_param: black, isort, prettier
parent
ddbc1926e8
commit
f8b51745f6
|
@ -10,18 +10,11 @@
|
||||||
Add new parameters for a paper format to be used by wkhtmltopdf
|
Add new parameters for a paper format to be used by wkhtmltopdf
|
||||||
command as arguments.
|
command as arguments.
|
||||||
""",
|
""",
|
||||||
"author": "Avoin.Systems,"
|
"author": "Avoin.Systems," "Eficent," "Odoo Community Association (OCA)",
|
||||||
"Eficent,"
|
|
||||||
"Odoo Community Association (OCA)",
|
|
||||||
"website": "https://avoin.systems",
|
"website": "https://avoin.systems",
|
||||||
"category": "Technical Settings",
|
"category": "Technical Settings",
|
||||||
"depends": [
|
"depends": ["web",],
|
||||||
"web",
|
"data": ["security/ir.model.access.csv", "views/paperformat.xml",],
|
||||||
],
|
|
||||||
"data": [
|
|
||||||
"security/ir.model.access.csv",
|
|
||||||
"views/paperformat.xml",
|
|
||||||
],
|
|
||||||
"installable": True,
|
"installable": True,
|
||||||
"auto_install": False,
|
"auto_install": False,
|
||||||
"application": False,
|
"application": False,
|
||||||
|
|
|
@ -6,7 +6,7 @@ from odoo import api, models
|
||||||
|
|
||||||
|
|
||||||
class IrActionsReport(models.Model):
|
class IrActionsReport(models.Model):
|
||||||
_inherit = 'ir.actions.report'
|
_inherit = "ir.actions.report"
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _build_wkhtmltopdf_args(
|
def _build_wkhtmltopdf_args(
|
||||||
|
@ -14,13 +14,11 @@ class IrActionsReport(models.Model):
|
||||||
paperformat_id,
|
paperformat_id,
|
||||||
landscape,
|
landscape,
|
||||||
specific_paperformat_args=None,
|
specific_paperformat_args=None,
|
||||||
set_viewport_size=False):
|
set_viewport_size=False,
|
||||||
|
):
|
||||||
# noinspection PyUnresolvedReferences,PyProtectedMember
|
# noinspection PyUnresolvedReferences,PyProtectedMember
|
||||||
command_args = super(IrActionsReport, self)._build_wkhtmltopdf_args(
|
command_args = super(IrActionsReport, self)._build_wkhtmltopdf_args(
|
||||||
paperformat_id,
|
paperformat_id, landscape, specific_paperformat_args, set_viewport_size
|
||||||
landscape,
|
|
||||||
specific_paperformat_args,
|
|
||||||
set_viewport_size
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for param in paperformat_id.custom_params:
|
for param in paperformat_id.custom_params:
|
||||||
|
|
|
@ -2,25 +2,25 @@
|
||||||
# Copyright 2017 Eficent Business and IT Consulting Services, S.L.
|
# Copyright 2017 Eficent Business and IT Consulting Services, S.L.
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import api, fields, models, _
|
|
||||||
from odoo.exceptions import ValidationError
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from odoo import _, api, fields, models
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Paper(models.Model):
|
class Paper(models.Model):
|
||||||
_inherit = 'report.paperformat'
|
_inherit = "report.paperformat"
|
||||||
|
|
||||||
custom_params = fields.One2many(
|
custom_params = fields.One2many(
|
||||||
'report.paperformat.parameter',
|
"report.paperformat.parameter",
|
||||||
'paperformat_id',
|
"paperformat_id",
|
||||||
'Custom Parameters',
|
"Custom Parameters",
|
||||||
help='Custom Parameters passed forward as wkhtmltopdf '
|
help="Custom Parameters passed forward as wkhtmltopdf " "command arguments",
|
||||||
'command arguments'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.constrains('custom_params')
|
@api.constrains("custom_params")
|
||||||
def _check_recursion(self):
|
def _check_recursion(self):
|
||||||
for paperformat in self:
|
for paperformat in self:
|
||||||
sample_html = """
|
sample_html = """
|
||||||
|
@ -33,11 +33,12 @@ class Paper(models.Model):
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
contenthtml = [bytes(sample_html, 'utf-8')]
|
contenthtml = [bytes(sample_html, "utf-8")]
|
||||||
report = self.env['ir.actions.report'].new({
|
report = self.env["ir.actions.report"].new(
|
||||||
'paperformat_id': paperformat.id
|
{"paperformat_id": paperformat.id}
|
||||||
})
|
)
|
||||||
content = report._run_wkhtmltopdf(contenthtml)
|
content = report._run_wkhtmltopdf(contenthtml)
|
||||||
if not content:
|
if not content:
|
||||||
raise ValidationError(_(
|
raise ValidationError(
|
||||||
"Failed to create a PDF using the provided parameters."))
|
_("Failed to create a PDF using the provided parameters.")
|
||||||
|
)
|
||||||
|
|
|
@ -1,25 +1,21 @@
|
||||||
# Copyright 2017 Avoin.Systems
|
# Copyright 2017 Avoin.Systems
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import models, fields
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
class ReportPaperformatParameter(models.Model):
|
class ReportPaperformatParameter(models.Model):
|
||||||
_name = 'report.paperformat.parameter'
|
_name = "report.paperformat.parameter"
|
||||||
_description = 'wkhtmltopdf parameters'
|
_description = "wkhtmltopdf parameters"
|
||||||
|
|
||||||
paperformat_id = fields.Many2one(
|
paperformat_id = fields.Many2one(
|
||||||
'report.paperformat',
|
"report.paperformat", "Paper Format", required=True,
|
||||||
'Paper Format',
|
|
||||||
required=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
name = fields.Char(
|
name = fields.Char(
|
||||||
'Name',
|
"Name",
|
||||||
required=True,
|
required=True,
|
||||||
help='The command argument name. Remember to add prefix -- or -'
|
help="The command argument name. Remember to add prefix -- or -",
|
||||||
)
|
)
|
||||||
|
|
||||||
value = fields.Char(
|
value = fields.Char("Value",)
|
||||||
'Value',
|
|
||||||
)
|
|
||||||
|
|
|
@ -10,23 +10,24 @@ from odoo.exceptions import ValidationError
|
||||||
@odoo.tests.common.post_install(True)
|
@odoo.tests.common.post_install(True)
|
||||||
class TestWkhtmltopdf(odoo.tests.TransactionCase):
|
class TestWkhtmltopdf(odoo.tests.TransactionCase):
|
||||||
def test_wkhtmltopdf_incorrect_parameter(self):
|
def test_wkhtmltopdf_incorrect_parameter(self):
|
||||||
for report_paperformat in self.env['report.paperformat'].search([]):
|
for report_paperformat in self.env["report.paperformat"].search([]):
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
report_paperformat.update({
|
report_paperformat.update(
|
||||||
'custom_params': [(0, 0, {
|
{"custom_params": [(0, 0, {"name": "bad-parameter"})]}
|
||||||
'name': 'bad-parameter'
|
)
|
||||||
})]})
|
|
||||||
|
|
||||||
def test_wkhtmltopdf_valid_parameter(self):
|
def test_wkhtmltopdf_valid_parameter(self):
|
||||||
for report_paperformat in self.env['report.paperformat'].search([]):
|
for report_paperformat in self.env["report.paperformat"].search([]):
|
||||||
error = False
|
error = False
|
||||||
try:
|
try:
|
||||||
report_paperformat.update({
|
report_paperformat.update(
|
||||||
'custom_params': [(0, 0, {
|
{"custom_params": [(0, 0, {"name": "--disable-smart-shrinking"})]}
|
||||||
'name': '--disable-smart-shrinking'
|
)
|
||||||
})]})
|
|
||||||
except ValidationError:
|
except ValidationError:
|
||||||
error = True
|
error = True
|
||||||
self.assertEquals(error, False,
|
self.assertEquals(
|
||||||
|
error,
|
||||||
|
False,
|
||||||
"There was an error adding wkhtmltopdf "
|
"There was an error adding wkhtmltopdf "
|
||||||
"parameter --disable-smart-shrinking")
|
"parameter --disable-smart-shrinking",
|
||||||
|
)
|
||||||
|
|
|
@ -1,21 +1,19 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<!-- FORM: report.paperformat -->
|
<!-- FORM: report.paperformat -->
|
||||||
<record id="paperformat_view_form_custom" model="ir.ui.view">
|
<record id="paperformat_view_form_custom" model="ir.ui.view">
|
||||||
<field name="name">paperformat with custom parameters</field>
|
<field name="name">paperformat with custom parameters</field>
|
||||||
<field name="model">report.paperformat</field>
|
<field name="model">report.paperformat</field>
|
||||||
<field name="inherit_id" ref="base.paperformat_view_form"/>
|
<field name="inherit_id" ref="base.paperformat_view_form" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="report_ids" position="after">
|
<field name="report_ids" position="after">
|
||||||
<field name="custom_params">
|
<field name="custom_params">
|
||||||
<tree editable="bottom">
|
<tree editable="bottom">
|
||||||
<field name="name"/>
|
<field name="name" />
|
||||||
<field name="value"/>
|
<field name="value" />
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
|
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
Loading…
Reference in New Issue