Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
2755 Widoki

It seems like a simple process, but clearly it is not. But maybe I'm asking the wrong question.

I am trying to export my products from my Odoo 12 database and import them into my new Odoo 16. The process works fine, except for the product images. 

When I export images from version 12, I get what appears to be a base64-encoded data string for the images. But as soon as I try to import this data, I get this error message: "Found invalid image data, images should be imported as either URLs or base64-encoded data".

There must be an easy way to import product images? If so please help.

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

This code is used for the CSV file importing, so you can export the image field and external_id from v12 after creating a script for importing the images :

Create a wizard and the wizard.py like this

from odoo import models, fields
import base64
import io
import csv


class DynamicImageField(models.TransientModel):
_name = 'import.photo'
_description = 'Import Photo'

file = fields.Binary('File')

def import_photo(self):

csv_data = base64.b64decode(self.file)

data_file = io.StringIO(csv_data.decode("utf-8"))

csv_reader = csv.reader(data_file, delimiter=',')
keys = ['id', 'image'] # these are the csv file header , we only take the external id and the image filed(binary)
file_reader = []
file_reader.extend(csv_reader)
for i in range(len(file_reader)):
field = list(map(str, file_reader[i]))
values = dict(zip(keys, field))
if values:
if i == 0:
continue
else:
product = self.env.ref(values['id'])
product.write({
'image_1920': values['photo']
})

Regards

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
lis 24
1661
1
lis 24
2163
1
paź 23
2865
3
gru 23
20764
0
maj 21
7594