Browse Source

[14.0][MIG] report_qweb_pdf_watermark

myc-14.0-py3o
fshah 4 years ago
parent
commit
a2a0007bf0
  1. 2
      .travis.yml
  2. 5
      report_qweb_pdf_watermark/README.rst
  3. 2
      report_qweb_pdf_watermark/__init__.py
  4. 54
      report_qweb_pdf_watermark/demo/report.xml
  5. 11
      report_qweb_pdf_watermark/models/report.py
  6. 1
      report_qweb_pdf_watermark/readme/CONTRIBUTORS.rst
  7. 12
      report_qweb_pdf_watermark/readme/HISTORY.rst
  8. 2
      report_qweb_pdf_watermark/tests/test_report_qweb_pdf_watermark.py

2
.travis.yml

@ -33,7 +33,7 @@ install:
- 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 WKHTMLTOPDF_VERSION=0.12.4
- export WKHTMLTOPDF_VERSION=0.12.5
- travis_install_nightly
script:

5
report_qweb_pdf_watermark/README.rst

@ -67,6 +67,11 @@ Changelog
* [MIG] Migration to V13.
14.0.1.0.0 (2021-01-29)
~~~~~~~~~~~~~~~~~~~~~~~
* [MIG] Migration to V14.
Bug Tracker
===========

2
report_qweb_pdf_watermark/__init__.py

@ -1,4 +1,4 @@
# © 2016 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models # pyflakes.ignore
from . import models

54
report_qweb_pdf_watermark/demo/report.xml

@ -1,28 +1,34 @@
<?xml version="1.0" encoding="UTF-8" ?>
<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="base.paperformat_euro"
/>
<record id="demo_report" model="ir.actions.report">
<field name="pdf_watermark_expression">docs[:1].company_id.logo</field>
</record>
<template id="demo_report_view">
<t t-call="web.html_container">
<t t-call="web.external_layout">
<div class="page">
<ul>
<li t-foreach="docs" t-as="doc">
<t t-esc="doc.name" />
</li>
</ul>
</div>
<data>
<record id="demo_reports" model="ir.actions.report">
<field name="name">Demo report</field>
<field name="model">res.users</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">report_qweb_pdf_watermark.demo_report_view</field>
<field name="report_file">report_qweb_pdf_watermark.demo_report_view</field>
<field name="paperformat_id" ref="base.paperformat_euro" />
<field name="binding_model_id" ref="base.model_res_users" />
<field name="binding_type">report</field>
</record>
<record id="demo_report" model="ir.actions.report">
<field name="name">Demo report</field>
<field name="model">res.users</field>
<field name="report_name">report_qweb_pdf_watermark.demo_report_view</field>
<field name="pdf_watermark_expression">docs[:1].company_id.logo</field>
</record>
<template id="demo_report_view">
<t t-call="web.html_container">
<t t-call="web.external_layout">
<div class="page">
<ul>
<li t-foreach="docs" t-as="doc">
<t t-esc="doc.name" />
</li>
</ul>
</div>
</t>
</t>
</t>
</template>
</template>
</data>
</odoo>

11
report_qweb_pdf_watermark/models/report.py

@ -6,7 +6,8 @@ from logging import getLogger
from PIL import Image
from odoo import api, fields, models, tools
from odoo import api, fields, models
from odoo.tools.safe_eval import safe_eval
try:
# we need this to be sure PIL has loaded PDF support
@ -34,12 +35,12 @@ 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, 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(
return super(Report, self.with_context(res_ids=res_ids))._render_qweb_pdf(
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(res_ids=res_ids, data=data)
@api.model
def _run_wkhtmltopdf(
@ -65,7 +66,7 @@ class Report(models.Model):
if self.pdf_watermark:
watermark = b64decode(self.pdf_watermark)
elif docids:
watermark = tools.safe_eval(
watermark = safe_eval(
self.pdf_watermark_expression or "None",
dict(env=self.env, docs=self.env[self.model].browse(docids)),
)

1
report_qweb_pdf_watermark/readme/CONTRIBUTORS.rst

@ -2,3 +2,4 @@
* Stefan Rijnhart <stefan@opener.am>
* Rod Schouteden <rod.schouteden@dynapps.be>
* Robin Goots <robin.goots@dynapps.be>
* Foram Shah <foram.shah@initos.com>

12
report_qweb_pdf_watermark/readme/HISTORY.rst

@ -2,3 +2,15 @@
~~~~~~~~~~~~~~~~~~~~~~~
* [MIG] Migration to V12.
13.0.1.0.0 (2021-01-27)
~~~~~~~~~~~~~~~~~~~~~~~
* [MIG] Migration to V13.
14.0.1.0.0 (2021-01-29)
~~~~~~~~~~~~~~~~~~~~~~~
* [MIG] Migration to V14.

2
report_qweb_pdf_watermark/tests/test_report_qweb_pdf_watermark.py

@ -27,7 +27,7 @@ class TestReportQwebPdfWatermark(HttpCase):
report = self.env["ir.model.data"].xmlid_to_object(
"report_qweb_pdf_watermark.demo_report"
)
pdf, _ = report.with_context(force_report_rendering=True).render_qweb_pdf(
pdf, _ = report.with_context(force_report_rendering=True)._render_qweb_pdf(
self.env["res.users"].search([]).ids
)
self.assertEqual(pdf.count(b"/Subtype /Image"), number)
Loading…
Cancel
Save