Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
1 Responder
2634 Visualizações

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.

Avatar
Cancelar
Melhor resposta

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

Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
2
nov. 24
1556
1
nov. 24
1973
1
out. 23
2714
3
dez. 23
20572
0
mai. 21
7484