Browse Source

Merge pull request #164 from Eficent/10.0-fix-report_qweb_pdf_watermark

[FIX] report_qweb_pdf_watermark: Fixes on tests and use pyPDF2
pull/174/head
Pedro M. Baeza 7 years ago
committed by GitHub
parent
commit
ee3f7bc70f
  1. 5
      report_qweb_pdf_watermark/README.rst
  2. 2
      report_qweb_pdf_watermark/__manifest__.py
  3. 20
      report_qweb_pdf_watermark/models/report.py
  4. 6
      report_qweb_pdf_watermark/tests/test_report_qweb_pdf_watermark.py
  5. 15
      report_qweb_signer/tests/test_report_qweb_signer.py

5
report_qweb_pdf_watermark/README.rst

@ -8,6 +8,11 @@ Pdf watermark
This module was written to add watermarks (backgrounds) to PDF reports. Because of the way wkhtmltopdf handles headers and footers in the current versions, it is quite impossible to have a background for the complete page using HTML and CSS. That is why this module inserts the image at the PDF level. This module was written to add watermarks (backgrounds) to PDF reports. Because of the way wkhtmltopdf handles headers and footers in the current versions, it is quite impossible to have a background for the complete page using HTML and CSS. That is why this module inserts the image at the PDF level.
Installation
============
This module works out of the box, but is faster if you install the python library PyPDF2.
Usage Usage
===== =====

2
report_qweb_pdf_watermark/__manifest__.py

@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
"name": "Pdf watermark", "name": "Pdf watermark",
"version": "10.0.1.0.0",
"version": "10.0.1.0.1",
"author": "Therp BV, " "author": "Therp BV, "
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",

20
report_qweb_pdf_watermark/models/report.py

@ -3,16 +3,22 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from base64 import b64decode from base64 import b64decode
from logging import getLogger from logging import getLogger
from pyPdf import PdfFileWriter, PdfFileReader
from pyPdf.utils import PdfReadError
from PIL import Image from PIL import Image
from StringIO import StringIO from StringIO import StringIO
from odoo import api, models, tools
from PIL import PdfImagePlugin # flake8: noqa
# PdfImagePlugin must be loaded in order to work PNG to PDF transformation
# This issue is related to Pillow creation, as can be seen in its source code:
# https://github.com/python-pillow/Pillow/blob/master/PIL/PdfImagePlugin.py
from pyPdf import PdfFileWriter, PdfFileReader
from pyPdf.utils import PdfReadError
try:
from PyPDF2 import PdfFileWriter, PdfFileReader # pylint: disable=W0404
from PyPDF2.utils import PdfReadError # pylint: disable=W0404
except ImportError:
pass
try:
# we need this to be sure PIL has loaded PDF support
from PIL import PdfImagePlugin # noqa: F401
except ImportError:
pass
from odoo import api, models, tools
logger = getLogger(__name__) logger = getLogger(__name__)

6
report_qweb_pdf_watermark/tests/test_report_qweb_pdf_watermark.py

@ -1,11 +1,13 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2016 Therp BV <http://therp.nl> # © 2016 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import TransactionCase
from PIL import Image
from odoo.tests.common import HttpCase
class TestReportQwebPdfWatermark(TransactionCase):
class TestReportQwebPdfWatermark(HttpCase):
def test_report_qweb_pdf_watermark(self): def test_report_qweb_pdf_watermark(self):
Image.init()
# with our image, we have three # with our image, we have three
self._test_report_images(3) self._test_report_images(3)

15
report_qweb_signer/tests/test_report_qweb_signer.py

@ -2,20 +2,17 @@
# Copyright 2017 Tecnativa - Pedro M. Baeza # Copyright 2017 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests import common
from odoo.tests.common import HttpCase
@common.at_install(False)
@common.post_install(True)
class TestReportQwebSigner(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestReportQwebSigner, cls).setUpClass()
cls.partner = cls.env['res.partner'].create({
class TestReportQwebSigner(HttpCase):
def setUp(self):
super(TestReportQwebSigner, self).setUp()
self.partner = self.env['res.partner'].create({
'name': 'Test partner', 'name': 'Test partner',
'customer': True, 'customer': True,
}) })
cls.report = cls.env.ref('report_qweb_signer.partner_demo_report')
self.report = self.env.ref('report_qweb_signer.partner_demo_report')
def test_report_qweb_signer(self): def test_report_qweb_signer(self):
self.env['report'].get_pdf( self.env['report'].get_pdf(

Loading…
Cancel
Save