Odoo Help


How can I import photos of my employees into HR module?

hr v7
Nahedh Alharbi
on 2/28/13, 4:38 AM 5,621 views

I have more than 800 .JPG photos for my employees, is there any way to import them into my HR module? I use OpenERP 7 which installed on UBUNTU 12.4 server.

Thank you in advance.




| 5 6 8
Cornwall, Canada

Analysing, designing, coding and mentoring since 1975. Kilobytes to terabytes. Punch cards to punchy sites. My OpenERP video series: http://www.youtube.com/playlist?list=PLq7op4J183lX44ZlXPiHxUpRvmmRDtxye My Google Speadsheets --> OpenERP Data Pump project: http://martinhbramwell.github.io/GData_OpenERP_Data_Pump My email (with spaces removed) : mhb . warehouseman @ gmail . com

On 2/28/13, 6:47 AM

First be sure you set "Allow users to import data from CSV files" in Settings >> General Settings. (In fact you must have the module base_import installed for even that to be possible) After you've done that, a new link will appear, beside the [Create] button in the List view (not Icon view) of the employee directory.

Probably you will need to export to CSV first and then open the CSV into a spreadsheet, in order to see what an import file should look like.

I tried it just now importing into a Google Docs spreadsheet, then downloading as a new CSV file and importing into OpenERP. I can confirm that this correctly created a new user from an existing one. The photo restored correctly, too.

To add new images to your spreadsheet you'll need to use a Base64 encoder

If your employee data is already installed you will face the problem of matching photos to persons. The solution to that is to choose one or two fields that together form some sort of unique identifier. Export just those fields to a file and import it into a spreadsheet workbook (Let's call that Sheet_1). You'll see that an additional "External ID" column will have been created in Sheet_1. Load your Base64 encoded images into a second sheet in the workbook (Sheet_2), keyed with the same unique identifier. In a third sheet (Sheet_3), use the VLOOKUP function on a person in Sheet_1 to get the "External ID" for each image in Sheet_2, and thus form a correctly formatted sheet for exporting back to OpenERP.

If you are just experimenting, you can quickly convert an image to Base64, with a site like http://base64.wutils.com/encoding-online/ for example.

On a "good" Linux distribution, you can just run this:

cat photo.jpg | base64 --wrap=0 > photo.b64

(--wrap=0 ensures no <cr><lf> cruft sneak into it)

Now, if you want to go completely loopy about this you can try ...

1) A bash script (MakeBase64CSV.sh) such as ...

echo \"name\",\"image\" > $1.csv
while IFS=, read f1 f2; do
    # echo "fields[$f1 $f2 $f3 $f4]"
    echo -n \"$f1\",\" >> $1.csv
    cat $f2 | base64 --wrap=0 >> $1.csv
    echo \" >> $1.csv
done < $1

2) . . . that expects a records file (PersonPix.txt) such as . . .

Bob Roberts, BobRoberts.png
Carol Karolice, CarolKarolice.png
Ted Edwards, TedEdwards.png
Alice Alder, AliceAlder.png

3) . . . that gets executed like this ...

./MakeBase64CSV.sh PersonPix.txt

4) . . . that can be viewed like this . . .

cat PersonPix.txt.csv

5) . . . spitting out something that'll look like this . . .

"Bob Roberts","2dd5xU1...milesOfTerrifyingGibberish...fn/3/dO2"
"Carol Karolice","9TU9Pd0...milesOfTerrifyingGibberish...9FwwgDAjKIT"
"Ted Edwards","53xC2vA...milesOfTerrifyingGibberish...DGxGCwkwF"
"Alice Alder","UBQqsm2...milesOfTerrifyingGibberish...yx9YtbHR"

"use a Base64 encoder" The key :) - now I can progress - many thanks

on 2/28/13, 6:59 AM

up votes gratefully received. :-) (bowing)

on 2/28/13, 7:14 AM

+1 A recipe for converting to base64 would be a great addition.

Daniel Reis
on 2/28/13, 9:02 AM

your weesh is mine command line

on 2/28/13, 10:01 AM

Great, It works with me, thank you very much Martin. :)

Nahedh Alharbi
on 3/2/13, 1:08 PM

Glad to help!

on 3/2/13, 1:25 PM

Not working. I keep getting No such file or directory on each line. It appears to not be parsing the file to base64 for some reason. Using Centos 6.4.

on 6/11/13, 10:14 PM

It turns out that the file name pair near the end of the CSV was incomplete. So if you get this error, check that each row has a matching image entry!!

on 6/12/13, 2:31 PM

Andreas Brueckl

--Andreas Brueckl--

| 7 8 7
Vienna, Austria
--Andreas Brueckl--
OpenERP Consulting and Development
Andreas Brueckl
On 2/28/13, 7:29 AM

I am a friend of python scripts using XMLRPC.

First you should rename all images before the import. Use the OpenERP-ID or the employee name as the image name.

In the script:

  • loop over all images
  • encode file with base64.encode()
  • perform write on object hr.employee with value {'image': b64data} using xmlrpclib
  • if you have named to file with the employee name you first have to search the OpenERP before you can perform the write

Thanks for the Hint! - Would it be possible to get a bit more detailed description ;) - Thanks in advance!

Michael Karrer
on 3/27/13, 7:58 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

4 follower(s)


Asked: 2/28/13, 4:38 AM
Seen: 5621 times
Last updated: 3/16/15, 8:10 AM