parent
d55b8b5453
commit
fe281ec4b8
|
@ -2,7 +2,7 @@
|
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
{
|
||||
"name": "Pdf watermark",
|
||||
"version": "15.0.1.0.0",
|
||||
"version": "16.0.1.0.0",
|
||||
"author": "Therp BV, " "Odoo Community Association (OCA)",
|
||||
"license": "AGPL-3",
|
||||
"category": "Technical Settings",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# © 2016 Therp BV <http://therp.nl>
|
||||
# Copyright 2023 Onestein - Anjeel Haria
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from base64 import b64decode
|
||||
from io import BytesIO
|
||||
|
@ -41,12 +42,14 @@ class Report(models.Model):
|
|||
"You have access to variables `env` and `docs`",
|
||||
)
|
||||
|
||||
def _render_qweb_pdf(self, res_ids=None, data=None):
|
||||
def _render_qweb_pdf(self, report_ref, res_ids=None, data=None):
|
||||
if not self.env.context.get("res_ids"):
|
||||
return super(Report, self.with_context(res_ids=res_ids))._render_qweb_pdf(
|
||||
res_ids=res_ids, data=data
|
||||
report_ref, res_ids=res_ids, data=data
|
||||
)
|
||||
return super(Report, self)._render_qweb_pdf(res_ids=res_ids, data=data)
|
||||
return super(Report, self)._render_qweb_pdf(
|
||||
report_ref, res_ids=res_ids, data=data
|
||||
)
|
||||
|
||||
def pdf_has_usable_pages(self, numpages):
|
||||
if numpages < 1:
|
||||
|
@ -63,6 +66,7 @@ class Report(models.Model):
|
|||
def _run_wkhtmltopdf(
|
||||
self,
|
||||
bodies,
|
||||
report_ref=False,
|
||||
header=None,
|
||||
footer=None,
|
||||
landscape=False,
|
||||
|
@ -71,6 +75,7 @@ class Report(models.Model):
|
|||
):
|
||||
result = super(Report, self)._run_wkhtmltopdf(
|
||||
bodies,
|
||||
report_ref=report_ref,
|
||||
header=header,
|
||||
footer=footer,
|
||||
landscape=landscape,
|
||||
|
@ -79,15 +84,23 @@ class Report(models.Model):
|
|||
)
|
||||
|
||||
docids = self.env.context.get("res_ids", False)
|
||||
report_sudo = self._get_report(report_ref)
|
||||
watermark = None
|
||||
if self.pdf_watermark:
|
||||
watermark = b64decode(self.pdf_watermark)
|
||||
elif self.use_company_watermark and self.env.company.pdf_watermark:
|
||||
if self.pdf_watermark or report_sudo.pdf_watermark:
|
||||
watermark = b64decode(self.pdf_watermark or report_sudo.pdf_watermark)
|
||||
elif (
|
||||
self.use_company_watermark or report_sudo.use_company_watermark
|
||||
) and self.env.company.pdf_watermark:
|
||||
watermark = b64decode(self.env.company.pdf_watermark)
|
||||
elif docids:
|
||||
watermark = safe_eval(
|
||||
self.pdf_watermark_expression or "None",
|
||||
dict(env=self.env, docs=self.env[self.model].browse(docids)),
|
||||
self.pdf_watermark_expression
|
||||
or report_sudo.pdf_watermark_expression
|
||||
or "None",
|
||||
dict(
|
||||
env=self.env,
|
||||
docs=self.env[self.model or report_sudo.model].browse(docids),
|
||||
),
|
||||
)
|
||||
if watermark:
|
||||
watermark = b64decode(watermark)
|
||||
|
|
|
@ -4,3 +4,4 @@
|
|||
* Robin Goots <robin.goots@dynapps.be>
|
||||
* Foram Shah <foram.shah@initos.com>
|
||||
* Emiel van Bokhoven <emiel@360erp.nl>
|
||||
* Anjeel Haria
|
||||
|
|
|
@ -21,3 +21,8 @@
|
|||
|
||||
* [MIG] Migration to V15.
|
||||
* Define pdf watermark in company settings
|
||||
|
||||
16.0.1.0.0 (2023-03-13)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* [MIG] Migration to V16.
|
||||
|
|
|
@ -367,7 +367,7 @@ ul.auto-toc {
|
|||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/reporting-engine/tree/15.0/report_qweb_pdf_watermark"><img alt="OCA/reporting-engine" src="https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/reporting-engine-15-0/reporting-engine-15-0-report_qweb_pdf_watermark"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/143/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
||||
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/reporting-engine/tree/16.0/report_qweb_pdf_watermark"><img alt="OCA/reporting-engine" src="https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/reporting-engine-15-0/reporting-engine-15-0-report_qweb_pdf_watermark"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/143/16.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
||||
<p>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.</p>
|
||||
<p><strong>Table of contents</strong></p>
|
||||
<div class="contents local topic" id="contents">
|
||||
|
@ -380,13 +380,14 @@ ul.auto-toc {
|
|||
<li><a class="reference internal" href="#id2" id="id10">13.0.1.0.0 (2021-01-27)</a></li>
|
||||
<li><a class="reference internal" href="#id3" id="id11">14.0.1.0.0 (2021-01-29)</a></li>
|
||||
<li><a class="reference internal" href="#id4" id="id12">15.0.1.0.0 (2022-01-11)</a></li>
|
||||
<li><a class="reference internal" href="#id4" id="id13">16.0.1.0.0 (2023-03-13)</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference internal" href="#bug-tracker" id="id13">Bug Tracker</a></li>
|
||||
<li><a class="reference internal" href="#credits" id="id14">Credits</a><ul>
|
||||
<li><a class="reference internal" href="#authors" id="id15">Authors</a></li>
|
||||
<li><a class="reference internal" href="#contributors" id="id16">Contributors</a></li>
|
||||
<li><a class="reference internal" href="#maintainers" id="id17">Maintainers</a></li>
|
||||
<li><a class="reference internal" href="#bug-tracker" id="id14">Bug Tracker</a></li>
|
||||
<li><a class="reference internal" href="#credits" id="id15">Credits</a><ul>
|
||||
<li><a class="reference internal" href="#authors" id="id16">Authors</a></li>
|
||||
<li><a class="reference internal" href="#contributors" id="id17">Contributors</a></li>
|
||||
<li><a class="reference internal" href="#maintainers" id="id18">Maintainers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -453,6 +454,12 @@ And demo report is available (if you have demo data installed) on the users form
|
|||
<li>Define pdf watermark in company settings</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="id19">
|
||||
<h2><a class="toc-backref" href="#id11">16.0.1.0.0 (2023-03-13)</a></h2>
|
||||
<ul class="simple">
|
||||
<li>[MIG] Migration to V16.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="bug-tracker">
|
||||
<h1><a class="toc-backref" href="#id13">Bug Tracker</a></h1>
|
||||
|
@ -479,6 +486,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
|
|||
<li>Robin Goots <<a class="reference external" href="mailto:robin.goots@dynapps.be">robin.goots@dynapps.be</a>></li>
|
||||
<li>Foram Shah <<a class="reference external" href="mailto:foram.shah@initos.com">foram.shah@initos.com</a>></li>
|
||||
<li>Emiel van Bokhoven <<a class="reference external" href="mailto:emiel@360erp.nl">emiel@360erp.nl</a>></li>
|
||||
<li>Anjeel Haria</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
|
@ -488,7 +496,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
|
|||
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.</p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/reporting-engine/tree/15.0/report_qweb_pdf_watermark">OCA/reporting-engine</a> project on GitHub.</p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/reporting-engine/tree/16.0/report_qweb_pdf_watermark">OCA/reporting-engine</a> project on GitHub.</p>
|
||||
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# © 2016 Therp BV <http://therp.nl>
|
||||
# Copyright 2023 Onestein - Anjeel Haria
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from PIL import Image
|
||||
|
||||
|
@ -36,9 +37,13 @@ class TestReportQwebPdfWatermark(HttpCase):
|
|||
self._test_report_images(3)
|
||||
|
||||
def _test_report_images(self, number):
|
||||
report = self.env.ref("report_qweb_pdf_watermark.demo_report")
|
||||
pdf, _ = report.with_context(force_report_rendering=True)._render_qweb_pdf(
|
||||
self.env["res.users"].search([]).ids
|
||||
pdf, _ = (
|
||||
self.env["ir.actions.report"]
|
||||
.with_context(force_report_rendering=True)
|
||||
._render_qweb_pdf(
|
||||
"report_qweb_pdf_watermark.demo_report",
|
||||
self.env["res.users"].search([]).ids,
|
||||
)
|
||||
)
|
||||
self.assertEqual(pdf.count(b"/Subtype /Image"), number)
|
||||
|
||||
|
|
Loading…
Reference in New Issue