Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
5215 Prikazi

i want to show image from model res.company.plogo which is binary custom field

how can we do that like scr="res.company.plogo" or any other solution to get image from model res.company.plogo and show here down

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

<templates id="template" xml:space="preserve">

<t t-extend="Chrome">

<t t-jquery=".pos-logo" t-operation="replace">

<img src="" style="padding: 5px; margin: 0px; height: 40px; width: 100px;" />

</t>

</t>

</templates>

Avatar
Opusti
Best Answer

Hi,

You'll need to utilize Odoo's templating language and change the src attribute of the img tag to the base64 encoding of the binary data in order to display an image from a binary custom field in the res.company model. How to do it is as follows:

1. Initially, confirm that you have the res.company.plogo field is correctly defined as a binary custom field in the res.company model.

2. To acquire the binary data of the res.company.plogo field and transform it to a base64 string, you must next develop a new controller. The src attribute of the image tag will contain the base64 string.

3. You can alter your XML template as follows, presuming you have already developed the custom controller and saved the base64 string in a variable named plogo_base64:

<?xml version="1.0" encoding="UTF-8" ?>
<templates id="template" xml:space="preserve">
    <t t-extend="Chrome">
        <t t-jquery=".pos-logo" t-operation="replace">
<img t-att-src="'data:image/png;base64,' + plogo_base64" style="padding: 5px; margin: 0px; height: 40px; width: 100px;" />
        </t>
    </t>
</templates>


Hope it helps

Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
1
jan. 23
2540
0
jun. 21
2509
2
jun. 17
8799
3
apr. 17
5534
1
maj 23
2786