[MIG] report_wkhtmltopdf_param: Migraton to 11.0

pull/278/head
Enric Tobella 2017-12-22 12:55:54 +01:00 committed by Abraham Anes
parent 322a8179ab
commit 0cd41fb18b
10 changed files with 35 additions and 33 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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): class IrActionsReport(models.Model):
_inherit = 'report' _inherit = 'ir.actions.report'
def _build_wkhtmltopdf_args(self, paperformat, @api.model
specific_paperformat_args=None): 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( command_args = super(IrActionsReport, self)._build_wkhtmltopdf_args(
paperformat, paperformat_id,
specific_paperformat_args 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])

View File

@ -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])] contenthtml = [bytes(sample_html, 'utf-8')]
content = self.env['report']._run_wkhtmltopdf( report = self.env['ir.actions.report'].new({
[], [], contenthtml, False, paperformat, False, False, False) '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."))

View File

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

View File

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

View File

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

View File

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