Skip to Content
Menu
This question has been flagged
1 Reply
5074 Views

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
Discard
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
Discard
Related Posts Replies Views Activity
1
Jan 23
2408
0
Jun 21
2409
2
Jun 17
8629
3
Apr 17
5449
1
May 23
2664