Browse Source

[MIG] report_wkhtmltopdf_param: Migraton to 11.0

pull/182/head
Enric Tobella 7 years ago
parent
commit
c4303cd808
No known key found for this signature in database GPG Key ID: 1A2546A1B7BA2451
  1. 8
      report_wkhtmltopdf_param/README.rst
  2. 3
      report_wkhtmltopdf_param/__init__.py
  3. 5
      report_wkhtmltopdf_param/__manifest__.py
  4. 3
      report_wkhtmltopdf_param/models/__init__.py
  5. 28
      report_wkhtmltopdf_param/models/report.py
  6. 11
      report_wkhtmltopdf_param/models/report_paperformat.py
  7. 3
      report_wkhtmltopdf_param/models/report_paperformat_parameter.py
  8. 3
      report_wkhtmltopdf_param/tests/__init__.py
  9. 2
      report_wkhtmltopdf_param/tests/test_report_paperformat.py
  10. 2
      report_wkhtmltopdf_param/views/paperformat.xml

8
report_wkhtmltopdf_param/README.rst

@ -1,5 +1,5 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
======================== ========================
@ -23,12 +23,11 @@ Usage
#. Go to *Settings* and press 'Activate the developer mode (with assets)' #. Go to *Settings* and press 'Activate the developer mode (with assets)'
#. Go to *Settings - Technical - Reports - Paper Format* #. Go to *Settings - Technical - Reports - Paper Format*
#. Add additional parameters indicating the command argument name (remember to #. Add additional parameters indicating the command argument name (remember to
add prefix -- or -) and value.
add prefix -- or -) and value.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/143/10.0
:target: https://runbot.odoo-community.org/runbot/143/11.0
Bug Tracker Bug Tracker
@ -53,7 +52,6 @@ Contributors
* Miku Laitinen <miku@avoin.systems> * Miku Laitinen <miku@avoin.systems>
* Jordi Ballester <jordi.ballester@eficent.com> * Jordi Ballester <jordi.ballester@eficent.com>
Maintainer Maintainer
---------- ----------

3
report_wkhtmltopdf_param/__init__.py

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

5
report_wkhtmltopdf_param/__manifest__.py

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Avoin.Systems # Copyright 2017 Avoin.Systems
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
# noinspection PyStatementEffect # noinspection PyStatementEffect
{ {
@ -17,7 +16,7 @@
"website": "https://avoin.systems", "website": "https://avoin.systems",
"category": "Technical Settings", "category": "Technical Settings",
"depends": [ "depends": [
"report",
"web",
], ],
"data": [ "data": [
"security/ir.model.access.csv", "security/ir.model.access.csv",

3
report_wkhtmltopdf_param/models/__init__.py

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

28
report_wkhtmltopdf_param/models/report.py

@ -1,23 +1,29 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Avoin.Systems # Copyright 2017 Avoin.Systems
# 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 (http://www.gnu.org/licenses/agpl).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models
from odoo import api, models
class Report(models.Model):
_inherit = 'report'
class IrActionsReport(models.Model):
_inherit = 'ir.actions.report'
def _build_wkhtmltopdf_args(self, paperformat,
specific_paperformat_args=None):
@api.model
def _build_wkhtmltopdf_args(
self,
paperformat_id,
landscape,
specific_paperformat_args=None,
set_viewport_size=False):
# noinspection PyUnresolvedReferences,PyProtectedMember # noinspection PyUnresolvedReferences,PyProtectedMember
command_args = super(Report, self)._build_wkhtmltopdf_args(
paperformat,
specific_paperformat_args
command_args = super(IrActionsReport, self)._build_wkhtmltopdf_args(
paperformat_id,
landscape,
specific_paperformat_args,
set_viewport_size
) )
for param in paperformat.custom_params:
for param in paperformat_id.custom_params:
command_args.extend([param.name]) command_args.extend([param.name])
if param.value: if param.value:
command_args.extend([param.value]) command_args.extend([param.value])

11
report_wkhtmltopdf_param/models/report_paperformat.py

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Avoin.Systems # Copyright 2017 Avoin.Systems
# 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 (http://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 import api, fields, models, _
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
@ -34,9 +33,11 @@ class Paper(models.Model):
</body> </body>
</html> </html>
""" """
contenthtml = [tuple([1, sample_html])]
content = self.env['report']._run_wkhtmltopdf(
[], [], contenthtml, False, paperformat, False, False, False)
contenthtml = [bytes(sample_html, 'utf-8')]
report = self.env['ir.actions.report'].new({
'paperformat_id': paperformat.id
})
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."))

3
report_wkhtmltopdf_param/models/report_paperformat_parameter.py

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Avoin.Systems # Copyright 2017 Avoin.Systems
# License AGPL-3.0 or later (http://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 models, fields

3
report_wkhtmltopdf_param/tests/__init__.py

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2017 Avoin.Systems # Copyright 2017 Avoin.Systems
# 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 (http://www.gnu.org/licenses/agpl).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import test_report_paperformat from . import test_report_paperformat

2
report_wkhtmltopdf_param/tests/test_report_paperformat.py

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2017 Avoin.Systems # Copyright 2017 Avoin.Systems
# 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 (http://www.gnu.org/licenses/agpl).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import odoo.tests import odoo.tests
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError

2
report_wkhtmltopdf_param/views/paperformat.xml

@ -4,7 +4,7 @@
<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="report.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">

Loading…
Cancel
Save