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

Hello,


a freelancer wrote month go a module, to add other images to a product.

I have this in my form view:

<field name="other_image_ids" widget="one2many_list" modifiers="{}"/>

When I made a new entry in the list, I have:

id: image, typ binary
id: name, typ char
id: sequence, type integer
id: description, type text

I have of course access to all files of the module.


I have a similar module, where I can add url for file downloads. This is in my import module:

                           if row['files']:
downloads = row['files']['downloads']
files = []
for f in downloads:
type = self.env['product.file.type'].search([('name', '=', f['type'])], limit=1)
if type and type.name == 'Datasheet':
skip_dt = True
if not type:
logger.error('************* File Type %s does not exists **************' % (f['type']))
for link in f['link']:
files.append((0,0, {'file_url': link,
'file_type_id': type.id}))
vals.update({'file_ids': files})

The datas come from a json with the id: otherImages. In the json the image is as base64 stored.


Can someone post please post the code to import the otherImages? 


Thank you!


Avatar
Discard
Best Answer

Hello Hannes,

I have done modification in your import module to write values in "other_image_ids".

//import python packages.
import base64
import urllib2

if row['files']:
downloads = row['files']['downloads']
files = []
image_list = []
for f in downloads:
type = self.env['product.file.type'].search([('name', '=', f['type'])], limit=1)
if type and type.name == 'Datasheet':
skip_dt = True
if not type:
logger.error('************ File Type %s does not exists *************' % (f['type']))
for link in f['link']:
files.append((0,0, {'file_url': link,
'file_type_id': type.id}))
//Read the image url.
image_list.append(base64.encodestring(urllib2.urlopen(link).read()))
//Update vals to write values to "other_image_ids"
vals.update({'file_ids': files, 'other_image_ids': [(6, 0, image_list)]})

Regards,

Aktiv software

Avatar
Discard