This question has been flagged
12 Replies
36999 Views

I'd like to know how to do batch import of images for the products and if its better import products first and then the products images or both at the same time.

Avatar
Discard

I am most interested in the straigh forward way. How is this?

I would first import the products (e.g. with the Import-Wizard) and afterwards I would import the product images. My tip to batch import images: rename the image files according to your products (.jpg or .jpg) Write a short python script which loops over the image files, encode with base64 and write to OpenERP with XMLRPC

Best Answer

Here the complete procedure for Linux users :

1/ import all your products

2/ export your products : this step is mandatory to get the external ID of your product. In my case I exported Name (that is mandatory) and ean13 since the picture's filename was name as follow :

ean13_code.jpg

3/ open your exported file (product.product.csv) with libreoffice and save it again with option "edit filter settings" in order to change the CSV separator to whatever else than ",". This is a little trick to avoid complicated script to deal with record that embed a coma.

4/ use the following script :

    #!/bin/bash
    # Usage : MakeBase64CSV.sh infile.csv outfile.csv
    # infile.csv columns are : externalID, name, filename or identifier
    # infile.csv separator MUST BE |

echo \"External ID\",\"Name\",\"image\" > $2

while IFS="|" read f1 f2 f3; do

    # recopy external ID and name
    echo -n $f1,\"$f2\", >> $2

    #If third column represents the picture's filename (not the key), please use this command
    #cat $(echo ${f3} | tr -d '\r' | tr -d '"') | base64 --wrap=0 >> $2

    #If third column represents the key to match with the filename, please use this command
    cat $(echo ${f3} | tr -d '\r' | tr -d '"').jpg | base64 --wrap=0 >> $2

    #Carrier return at end of line
    echo  >> $2
done < $1

5/ then use your script

./MakeBase64CSV.sh product.product.csv out.csv

In my example, all the pictures are in the same directory.

6/ you can now import your file out.csv into openERP. (Don't forget to change the CSV separator).

7/ If you run into the following error :

field larger than field limit (131072)

Please do the following :

  • modify the file addons/base_import/models.py
  • add the following line at the very begining of the _convert_import_data function :

    csv.field_size_limit(2097152)

  • delete the file addons/base_import/models.pyc

  • restart your server
  • redo the import of your out.csv file
Avatar
Discard

hi Marc, would you mind to correct the line that has been identified as faulty (if the complaint is correct)?

Best Answer

I encountered a few problems when using Marc's steps, but I sorted it out.

  1. The one but last line in the bash script needs to be echo \" >> $2, and not echo >> $2
  2. I ran into the field limit, mentioned in step 7. Adding the line csv.field_size_limit(2097152) did not help. Instead, I added the line at the very top of the function _read_csv in models.py

After making these changes, I was able to generate an import file, and to import pictures to my products.

Bart

Avatar
Discard

Hi Bart, you solved it? I did the script but when i try to import "out.cvs" on "odoo import page", the system doesn't recognice the file. Would you explain me how you did? At least until you gave the error... Thanks

Best Answer

I have uploaded a module on odoo apps that can help achieve this need.  https://apps.odoo.com/apps/modules/9.0/product_image_from_url/ 

My module employs the concept of importing the images as URLs using a normal csv/ excel import file. You can then download the images from the imported URLs in batch. I hope this will help.

Avatar
Discard
Best Answer

Dear all,

thanks for this post. I managed to create an upload file for my pictures.

Unfortunately i run into the "field larger than field limit" error. I tried to add the "csv.field_size_limit(2097152)" into the model.py file, deleted the models.pyc file and restarted the server.

However no matter where i put the csv.field_size_limit statement the openerp either does not work or shows the same failure.

Could you please post specify more precisly where i have to put the csv.field_size_limit?

thanks, Thomas

Avatar
Discard
Best Answer

Is need to put the line csv.field_size_limit(2097152) (or a bigger number. Depends of image size) in lines 230 and 271, next to "_read_csv" and "convert_import_data" lines into addons/base_import/models.py file.

Then follow the instructions above.

 

Avatar
Discard

Your file should have the extension csv NOT cvs!

Yes. Mi file ("out.csv") have a CSV extension. My mistake was in having skipped the step of modifying "csv.field_size_limit (2097152)". Now it works! Thanks for your answer

Best Answer

Is need to put the line csv.field_size_limit(2097152) (or a bigger number) in lines 230 and 271, next to "_read_csv" and "convert_import_data" lines into addons/base_import/models.py file.

Then follow the instructions above.

Avatar
Discard