Browse Source

[MIG] report_qweb_pdf_watermark

myc-14.0-py3o
Stefan Rijnhart 8 years ago
committed by fshah
parent
commit
ab7de7a93c
  1. 7
      report_qweb_pdf_watermark/README.rst
  2. 2
      report_qweb_pdf_watermark/__manifest__.py
  3. 52
      report_qweb_pdf_watermark/demo/report.xml
  4. 2
      report_qweb_pdf_watermark/models/ir_actions_report_xml.py
  5. 19
      report_qweb_pdf_watermark/models/report.py
  6. 5
      report_qweb_pdf_watermark/tests/test_report_qweb_pdf_watermark.py
  7. 24
      report_qweb_pdf_watermark/views/ir_actions_report_xml.xml

7
report_qweb_pdf_watermark/README.rst

@ -6,9 +6,7 @@
Pdf watermark Pdf watermark
============= =============
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 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.
Usage Usage
===== =====
@ -17,7 +15,7 @@ To use this module, you need to:
#. go to your report #. go to your report
#. select a PDF or image to use as watermark. Note that resolutions and size must match, otherwise you'll have funny results #. select a PDF or image to use as watermark. Note that resolutions and size must match, otherwise you'll have funny results
#. advanced users (members of group technical settings) can also fill in an expression that returns the data (base64 encoded) to be used as watermark
#. You can also fill in an expression that returns the data (base64 encoded) to be used as watermark
.. 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
@ -43,6 +41,7 @@ Contributors
------------ ------------
* Holger Brunn <hbrunn@therp.nl> * Holger Brunn <hbrunn@therp.nl>
* Stefan Rijnhart <stefan@opener.am>
Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:community@mail.odoo.com>`_ or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues. Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:community@mail.odoo.com>`_ or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues.

2
report_qweb_pdf_watermark/__openerp__.py → 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": "9.0.1.0.0",
"version": "10.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)", "author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"category": "Reporting", "category": "Reporting",

52
report_qweb_pdf_watermark/demo/report.xml

@ -1,30 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<report
id="demo_report"
string="Demo report"
model="res.users"
report_type="qweb-pdf"
name="report_qweb_pdf_watermark.demo_report_view"
file="report_qweb_pdf_watermark.demo_report_view"
paperformat="report.paperformat_euro"
<odoo>
<report
id="demo_report"
string="Demo report"
model="res.users"
report_type="qweb-pdf"
name="report_qweb_pdf_watermark.demo_report_view"
file="report_qweb_pdf_watermark.demo_report_view"
paperformat="report.paperformat_euro"
/> />
<record id="demo_report" model="ir.actions.report.xml">
<field name="pdf_watermark_expression">docs[:1].company_id.logo</field>
</record>
<template id="demo_report_view">
<t t-call="report.html_container">
<t t-call="report.external_layout">
<div class="page">
<ul>
<li t-foreach="docs" t-as="doc">
<t t-esc="doc.name" />
</li>
</ul>
</div>
</t>
<record id="demo_report" model="ir.actions.report.xml">
<field name="pdf_watermark_expression">docs[:1].company_id.logo</field>
</record>
<template id="demo_report_view">
<t t-call="report.html_container">
<t t-call="report.external_layout">
<div class="page">
<ul>
<li t-foreach="docs" t-as="doc">
<t t-esc="doc.name" />
</li>
</ul>
</div>
</t> </t>
</template>
</data>
</openerp>
</t>
</template>
</odoo>

2
report_qweb_pdf_watermark/models/ir_actions_report_xml.py

@ -1,7 +1,7 @@
# -*- 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 import fields, models
from odoo import fields, models
class IrActionsReportXml(models.Model): class IrActionsReportXml(models.Model):

19
report_qweb_pdf_watermark/models/report.py

@ -7,32 +7,25 @@ from pyPdf import PdfFileWriter, PdfFileReader
from pyPdf.utils import PdfReadError from pyPdf.utils import PdfReadError
from PIL import Image from PIL import Image
from StringIO import StringIO from StringIO import StringIO
from openerp import api, models, tools
from odoo import api, models, tools
logger = getLogger(__name__) logger = getLogger(__name__)
class Report(models.Model): class Report(models.Model):
_inherit = 'report' _inherit = 'report'
@api.v7
def get_pdf(
self, cr, uid, ids, report_name, html=None, data=None, context=None
):
# pylint: disable=R8110
# this override cannot be done in v8 api
@api.model
def get_pdf(self, docids, report_name, html=None, data=None):
result = super(Report, self).get_pdf( result = super(Report, self).get_pdf(
cr, uid, ids, report_name, html=html, data=data,
context=context
)
report = self._get_report_from_name(cr, uid, report_name)
docids, report_name, html=html, data=data)
report = self._get_report_from_name(report_name)
watermark = None watermark = None
if report.pdf_watermark: if report.pdf_watermark:
watermark = b64decode(report.pdf_watermark) watermark = b64decode(report.pdf_watermark)
else: else:
env = api.Environment(cr, uid, context)
watermark = tools.safe_eval( watermark = tools.safe_eval(
report.pdf_watermark_expression or 'None', report.pdf_watermark_expression or 'None',
dict(env=env, docs=env[report.model].browse(ids)),
dict(env=self.env, docs=self.env[report.model].browse(docids)),
) )
if watermark: if watermark:
watermark = b64decode(watermark) watermark = b64decode(watermark)

5
report_qweb_pdf_watermark/tests/test_report_qweb_pdf_watermark.py

@ -22,11 +22,8 @@ class TestReportQwebPdfWatermark(TransactionCase):
self._test_report_images(3) self._test_report_images(3)
def _test_report_images(self, number): def _test_report_images(self, number):
pdf = self.registry['report'].get_pdf(
self.cr,
self.uid,
pdf = self.env['report'].get_pdf(
self.env['res.users'].search([]).ids, self.env['res.users'].search([]).ids,
'report_qweb_pdf_watermark.demo_report_view', 'report_qweb_pdf_watermark.demo_report_view',
context={}
) )
self.assertEqual(pdf.count('/Subtype /Image'), number) self.assertEqual(pdf.count('/Subtype /Image'), number)

24
report_qweb_pdf_watermark/views/ir_actions_report_xml.xml

@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="act_report_xml_view" model="ir.ui.view">
<field name="model">ir.actions.report.xml</field>
<field name="inherit_id" ref="base.act_report_xml_view" />
<field name="arch" type="xml">
<field name="attachment" position="after">
<field name="pdf_watermark" attrs="{'invisible': [('report_type', '!=', 'qweb-pdf')]}" />
<field name="pdf_watermark_expression" attrs="{'invisible': [('report_type', '!=', 'qweb-pdf')]}" groups="base.group_no_one" />
</field>
<odoo>
<record id="act_report_xml_view" model="ir.ui.view">
<field name="model">ir.actions.report.xml</field>
<field name="inherit_id" ref="base.act_report_xml_view" />
<field name="arch" type="xml">
<field name="attachment" position="after">
<field name="pdf_watermark" attrs="{'invisible': [('report_type', '!=', 'qweb-pdf')]}" />
<field name="pdf_watermark_expression" attrs="{'invisible': [('report_type', '!=', 'qweb-pdf')]}" groups="base.group_no_one" />
</field> </field>
</record>
</data>
</openerp>
</field>
</record>
</odoo>
Loading…
Cancel
Save