[14.0][MIG] report_qweb_pdf_watermark
parent
2803a7c395
commit
518698a112
|
@ -67,6 +67,11 @@ Changelog
|
|||
|
||||
* [MIG] Migration to V13.
|
||||
|
||||
14.0.1.0.0 (2021-01-29)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* [MIG] Migration to V14.
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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)),
|
||||
)
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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…
Reference in New Issue