Skip to Content
Menu
This question has been flagged
2 Replies
3086 Views

What would be the most efficient strategy to import product images into a V15 db when the original product images are stored into a v14 db?

I know how to import and export data using  Odoo dedicated menus. 

However as images as concerned the export seems to geneate cell contents that are to long to be 100% exported; preventing reimport with 100% success.

Any direction on how to do this transfer from one odoo db to another one will be helpful.


Avatar
Discard
Best Answer

Hi  Thomas,

I think this video can help you: https://www.youtube.com/watch?v=VMJ0UI1crz4&list=PLSKcWRTtEl5qzvRaI-VTGavfReiHS_EEb&index=3

Avatar
Discard
Best Answer

Hi

First, you export the images field with the external id, eg you need to move the employee's images from v14 to 15
try to export the external id and the image filed and after you must write a wizard action and try to put the below code into it 

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


class DynamicField(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', 'photo']
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:
employee = self.env.ref(values['id'])
employee.write({
'image_1920': values['photo']
})

XML:

<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <record model='ir.ui.view' id='wizard_employee_photo_import'>
 
      <field name="name">import.photo</field>
        <field name="model">import.photo</field>
        <field name="arch" type="xml">
            <form string="Import">
                <sheet>
                    <group>
                        <group string="Import">
                            <field name="file"/>
                        </group>
                    </group>
                </sheet>
                <footer>
                    <button name="import_photo" string="Import" type="object" class="oe_highlight"/>
                    or
                    <button string="Cancel" class="oe_link" special="cancel"/>
                </footer>
            </form>
        </field>
    </record>


Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
1
Apr 25
1368
1
Mar 23
2734
1
Mar 22
1322
0
Feb 19
2881
1
Jul 25
1516