Browse Source

[ADD] module 'report_wkhtmltopdf_param'

pull/127/head
Miku Laitinen 8 years ago
committed by Jordi Ballester
parent
commit
058a09d0ad
  1. 70
      report_wkhtmltopdf_param/README.rst
  2. 5
      report_wkhtmltopdf_param/__init__.py
  3. 30
      report_wkhtmltopdf_param/__manifest__.py
  4. 7
      report_wkhtmltopdf_param/models/__init__.py
  5. 25
      report_wkhtmltopdf_param/models/report.py
  6. 42
      report_wkhtmltopdf_param/models/report_paperformat.py
  7. 26
      report_wkhtmltopdf_param/models/report_paperformat_parameter.py
  8. 3
      report_wkhtmltopdf_param/security/ir.model.access.csv
  9. BIN
      report_wkhtmltopdf_param/static/description/icon.png
  10. 5
      report_wkhtmltopdf_param/tests/__init__.py
  11. 33
      report_wkhtmltopdf_param/tests/test_report_paperformat.py
  12. 21
      report_wkhtmltopdf_param/views/paperformat.xml

70
report_wkhtmltopdf_param/README.rst

@ -0,0 +1,70 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
========================
Report Wkhtmltopdf Param
========================
This module allows you to add new parameters for a paper format which are
then forwarded to wkhtmltopdf command as arguments. To display the arguments
that wkhtmltopdf accepts go to your command line and type 'wkhtmltopdf -H'.
A commonly used parameter in Odoo is *--disable-smart-shrinking*, that will
disable the automatic resizing of the PDF when converting. This is
important when you intend to have a layout that conforms to certain alignment.
It is very common whenever you need to conform the PDF to a predefined
layoyut (e.g. checks, official forms,...).
Usage
=====
#. Go to *Settings* and press 'Activate the developer mode (with assets)'
#. Go to *Settings - Technical - Reports - Paper Format*
#. Add additional parameters indicating the command argument name (remember to
add prefix -- or -) and value.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/143/10.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Miku Laitinen <miku@avoin.systems>
* Jordi Ballester <jordi.ballester@eficent.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

5
report_wkhtmltopdf_param/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Avoin.Systems
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models

30
report_wkhtmltopdf_param/__manifest__.py

@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Avoin.Systems
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# noinspection PyStatementEffect
{
"name": "Report Wkhtmltopdf Param",
"version": "10.0.1.0.1",
"license": "AGPL-3",
"summary": """
Add new parameters for a paper format to be used by wkhtmltopdf
command as arguments.
""",
"author": "Avoin.Systems,"
"Eficent,"
"Odoo Community Association (OCA)",
"website": "https://avoin.systems",
"category": "Technical Settings",
"depends": [
"report",
],
"data": [
"security/ir.model.access.csv",
"views/paperformat.xml",
],
"installable": True,
"auto_install": False,
"application": False,
"active": False,
}

7
report_wkhtmltopdf_param/models/__init__.py

@ -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

@ -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

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

26
report_wkhtmltopdf_param/models/report_paperformat_parameter.py

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

3
report_wkhtmltopdf_param/security/ir.model.access.csv

@ -0,0 +1,3 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"paperformat_parameter_access_portal","ir_actions_report_paperformat_parameter group_portal","model_report_paperformat_parameter","base.group_portal",1,0,0,0
"paperformat_parameter_access_employee","ir_actions_report_paperformat_parameter group_hr_user","model_report_paperformat_parameter",,1,0,1,0

BIN
report_wkhtmltopdf_param/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

5
report_wkhtmltopdf_param/tests/__init__.py

@ -0,0 +1,5 @@
# -*- 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 . import test_report_paperformat

33
report_wkhtmltopdf_param/tests/test_report_paperformat.py

@ -0,0 +1,33 @@
# -*- 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).
import odoo.tests
from odoo.exceptions import ValidationError
@odoo.tests.common.at_install(False)
@odoo.tests.common.post_install(True)
class TestWkhtmltopdf(odoo.tests.TransactionCase):
def test_wkhtmltopdf_incorrect_parameter(self):
for report_paperformat in self.env['report.paperformat'].search([]):
with self.assertRaises(ValidationError):
report_paperformat.update({
'custom_params': [(0, 0, {
'name': 'bad-parameter'
})]})
def test_wkhtmltopdf_valid_parameter(self):
for report_paperformat in self.env['report.paperformat'].search([]):
error = False
try:
report_paperformat.update({
'custom_params': [(0, 0, {
'name': '--disable-smart-shrinking'
})]})
except ValidationError:
error = True
self.assertEquals(error, False,
"There was an error adding wkhtmltopdf "
"parameter --disable-smart-shrinking")

21
report_wkhtmltopdf_param/views/paperformat.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- FORM: report.paperformat -->
<record id="paperformat_view_form_custom" model="ir.ui.view">
<field name="name">paperformat with custom parameters</field>
<field name="model">report.paperformat</field>
<field name="inherit_id" ref="report.paperformat_view_form"/>
<field name="arch" type="xml">
<field name="report_ids" position="after">
<field name="custom_params">
<tree editable="bottom">
<field name="name"/>
<field name="value"/>
</tree>
</field>
</field>
</field>
</record>
</odoo>
Loading…
Cancel
Save