2

I would like to display images which are uploaded by users in my custom Qweb reports.

Which is the best way to do that?

ChesuCR
  • 9,352
  • 5
  • 51
  • 114
Chandu
  • 2,053
  • 3
  • 25
  • 39
  • Possible duplicate of [Display image in QWeb report](http://stackoverflow.com/questions/28561121/display-image-in-qweb-report) – Rutul Raval Oct 26 '15 at 09:50
  • Hi this question is not duplicate of that one. There he mentioned about header and footer that i have already done. but when it comes to inserting image in the page. blank image is showing... what to do?? any idea...!! Thanks – Chandu Oct 26 '15 at 09:55
  • could you plz help me out? – Chandu Oct 26 '15 at 11:11
  • Hi please refer to this link as well. http://stackoverflow.com/questions/30149379/picture-in-odoo-qweb-report Can you please provide what code have you done till now ? It would be easier to guide you. – Rutul Raval Oct 26 '15 at 13:06
  • Do you want to show a picture which is stored in the database or physically saved as a normal file? – ChesuCR Oct 26 '15 at 23:07
  • hi , i want to store the picture which is already stored in some records of DB. – Chandu Oct 27 '15 at 04:10
  • http://localhost:8069/web/binary/image?model=book.room&id=2&field=image&t=1445919360006 – Chandu Oct 27 '15 at 04:17
  • Hello, how to replace image in other field value? /like .png image/ – С. Дэлгэрцэцэг Aug 01 '18 at 08:32

4 Answers4

6

If you want to show an image from the database you can just use the image widget like this:

<span t-field="o.image_field_name" t-field-options='{"widget": "image"}'/>

And if you want to show an image stored as a file:

<img t-att-src="'/module_name/static/src/img/image_name.png'" />

Note: respect the order and the type of the quotes

ChesuCR
  • 9,352
  • 5
  • 51
  • 114
3

For someone who lands here from Google... For dynamic images from the database, one can use

<img t-attf-src="data:image/*;base64,{{o.image_field_name}}"/>

...where o.image_field_name is a dynamic field from the database/model. I prefer the <img/> tag over a <span/> for images.

To show a static image, use plain HTML.

<img src="path/to/image/file" alt="Alternate Text"/>

Note: alternate text attribute in an image does not add value in PDF reports. They don't show up when the image is missing, as in HTML.

Tirtha R
  • 1,148
  • 1
  • 14
  • 24
1

Sometimes you need to call a function from QWeb and get image. This code help me to read proper image field and print it with QWeb.

    <t t-foreach="get_image(id)" t-as="image_browse">
         <span t-field="image_browse.image" t-field-options='{"widget": "image"}'/> 
</t>

image_browse is a browse of id that send by get_image(id)

Esmaeil
  • 558
  • 5
  • 11
1
<tr t-foreach="o.pack_operation_ids" t-as="pack_operation">
    <td>
      <span t-field="pack_operation.product_id.image_small" t-field-options='{"widget": "image"}'/>
    </td>
</tr>
  • QWeb has an iteration directive foreach which take an expression returning the collection to iterate on, and a second parameter t-as providing the name to use for the "current item" of the iteration:
  • In <span> I access Image of product_id using pack.operation
  • You can select size of image like: image_small and image_medium
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Tejas Thakar
  • 585
  • 5
  • 19