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

New API, how to add image from specified location based on < field name="item_nr"/>, this field will contain number related to the image ...

create link or load directly into form ?


Avatar
Discard
Best Answer

option 1 (same image in all records, may be externally stored, inserting by url):

you can mix html & form record, so you can add any image (if you have link to it) using ordinary HTML img tag, so in your form:

<record id="some_id" model="ir.ui.view">
...........
...........
<field name="arch" type="xml">
<form string="Some STR">
<sheet> ....
<img src="http://example.com/some.jpg" style="width:300;height:200;"/>
...........


option 2 (different image per record, stored in odoo using binary field):

If you'll use binary field (the fields.Binary one...) to store images in odoo, then you can use widget="image" in your xml, example:

<field name="my_binary_field_name" widget="image" />

(of course you've to add "my_binary_field_name" binary field in your model as well, in python code...) 

see example here: Odoo_8.0/openerp/addons/base/res/res_company_view.xml#L22 


option 3 (different image per record, possibly externally stored, inserting by url using custom widget):

say field "image_url" is a char field containing image url, or such a part of it (as your number in "item_nr"?) that makes it possible to build full url, then in your XML you'll have:

<field name="image_url" widget="my_image_widget" />

here "my_image_widget" is a custom widget you've to implement in javascript. you should generate ordinary html image tag (similar to one in option 1) from inside your custom widget, using value of "image_url" field.

Avatar
Discard

there may be more/better options... good luck ;)

Nice effort Temur ! +1

Nice answer