Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
3576 Vues

I have an image field in a model that inherit from res_company with upload button, and I have a report that already print all company's data. 

For this report I have a background-image for a div as inlinin  style. 

My question: How to add this image from database as a "url" for background-image, thanks. 

*I can provide you with the code if you are interested to solve it.


Avatar
Ignorer
Meilleure réponse

Hi,

For that first, we need to set the fields for images, also we can set the colors, or style as per our needs,

In the py:


from odoo import api, fields, models


class ResCompany(models.Model):
"""Introduce watermark in pdf reports"""
_inherit = 'res.company'

watermark = fields.Boolean(string='Watermark', help='Enable it, while you '
'want to apply '
'watermark on your '
'pdf reports'
)
content_text = fields.Char(string='Text', help="Have the text here")
watermark_type = fields.Selection([
('image', 'Image'),
('text', 'Text'),
('logo', 'Logo'),
], default='text', help='Select the watermark type')
color_picker = fields.Char(string='Color Picker', help='Select the Color')
font_size = fields.Integer(string='Font size', default=30,
help="Mention the font size")
background_image = fields.Image(string='Image', help='Select the image')
rotating_angle = fields.Float(string='Angle of Rotation',
help='Mention the angle of rotation')

Then set the View, we need to define the XML file 

<?xml version="1.0" encoding="utf-8"?>

<!--Apply the watermark to the pdf report with mentioned specifications-->

<odoo>

<template id="pdf_watermark_report"

inherit_id="web.external_layout_standard">

<xpath expr="//div[hasclass('row')][last()]" position="after">

<t t-if="company.watermark">

<center>

<div class="row"

style="opacity:0.15; font-size:100px;text-align:center;top:500px;position:fixed;z-index:99;">

<div class="col-6" name="watermark">

<span

t-attf-style="-webkit-transform:rotate(-{{company.rotating_angle}}deg);color:{{company.color_picker}};font-size:{{company.font_size}}px;text-align:center;position:absolute;text-align:center;opacity:0.9;align:center;width:880px;">

<t t-if="company.watermark_type == 'text'">

<t t-esc="company.content_text"/>

</t>

<span style="width:880px;align:center;">

<t t-if="company.watermark_type == 'image'">

<img t-if="company.background_image"

t-att-src="image_data_uri(company.background_image)"

width="250" height="200"

/>

</t>

<t t-if="company.watermark_type == 'logo'">

<img t-if="company.logo"

t-att-src="image_data_uri(company.logo)"

width="250" height="200"/>

</t>

</span>

</span>

</div>

</div>

</center>

</t>

</xpath>

</template>

</odoo>

Hope it helps

Avatar
Ignorer

Kudos for this!

Very nice solution !

Publications associées Réponses Vues Activité
4
janv. 25
44640
0
oct. 24
1480
0
oct. 24
5
1
mai 23
3017
5
mai 21
11557