Browse Source

Merge pull request #141 from hbrunn/9.0-report_qweb_pdf_watermark

[IMP] use PyPDF2 if possible
pull/166/head
Pedro M. Baeza 7 years ago
committed by GitHub
parent
commit
631fd60345
  1. 12
      .travis.yml
  2. 5
      report_qweb_pdf_watermark/README.rst
  3. 2
      report_qweb_pdf_watermark/__openerp__.py
  4. 14
      report_qweb_pdf_watermark/models/report.py
  5. 6
      report_qweb_pdf_watermark/tests/test_report_qweb_pdf_watermark.py

12
.travis.yml

@ -1,14 +1,12 @@
sudo: false sudo: false
dist: trusty
cache: pip cache: pip
addons: addons:
sources:
- pov-wkhtmltopdf
apt: apt:
packages: packages:
- expect-dev # provides unbuffer utility - expect-dev # provides unbuffer utility
- python-lxml # because pip installation is slow - python-lxml # because pip installation is slow
- wkhtmltopdf # report tests
language: python language: python
@ -19,6 +17,7 @@ env:
global: global:
- VERSION="9.0" TESTS="0" LINT_CHECK="0" TRANSIFEX="0" - VERSION="9.0" TESTS="0" LINT_CHECK="0" TRANSIFEX="0"
- TRANSIFEX_USER='transbot@odoo-community.org' - TRANSIFEX_USER='transbot@odoo-community.org'
- WKHTMLTOPDF_VERSION=0.12.4
- secure: NUsXwVrMntcqge1ozKW+DSkP7dq+Rla6JVvFF2c89/g+zJaIqQRi8EQBLoqNwCdMk+rjpQeZt/JPELjH+EzPcmGddhDxOgVB3nUT9LvFXGCHF+NjmHXqyba4tuc7BnpG1WDD+rSlxVCt1aIjNIhhaZ4ic0rCWpKNYu/yFTsmChc= - secure: NUsXwVrMntcqge1ozKW+DSkP7dq+Rla6JVvFF2c89/g+zJaIqQRi8EQBLoqNwCdMk+rjpQeZt/JPELjH+EzPcmGddhDxOgVB3nUT9LvFXGCHF+NjmHXqyba4tuc7BnpG1WDD+rSlxVCt1aIjNIhhaZ4ic0rCWpKNYu/yFTsmChc=
matrix: matrix:
- LINT_CHECK="1" - LINT_CHECK="1"
@ -26,13 +25,6 @@ env:
- TESTS="1" ODOO_REPO="odoo/odoo" - TESTS="1" ODOO_REPO="odoo/odoo"
- TESTS="1" ODOO_REPO="OCA/OCB" - TESTS="1" ODOO_REPO="OCA/OCB"
virtualenv:
system_site_packages: true
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
install: install:
- git clone --depth=1 https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools - git clone --depth=1 https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH} - export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}

5
report_qweb_pdf_watermark/README.rst

@ -10,6 +10,11 @@ This module was written to add watermarks (backgrounds) to PDF reports.
This is necessary because of the way wkhtmltopdf handles headers and footers, in the current versions if quite impossible to have a background for the complete page. This is necessary because of the way wkhtmltopdf handles headers and footers, in the current versions if quite impossible to have a background for the complete page.
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/__openerp__.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": "9.0.1.0.0",
"version": "9.0.1.0.1",
"author": "Therp BV,Odoo Community Association (OCA)", "author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"category": "Reporting", "category": "Reporting",

14
report_qweb_pdf_watermark/models/report.py

@ -3,10 +3,20 @@
# 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 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 openerp import api, models, tools from openerp 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 openerp.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)

Loading…
Cancel
Save