Odoo Help


Importing products from CSV direct to Database

on 5/21/13, 7:37 PM 3,533 views

Hi, Im trying to import products list directly to the database using an script found...

Using this tutorial I have created my own script as follows:

import csv
import psycopg2

conn_string = "host='localhost' dbname='uuuu' user='openerp' password='uuuuu'"
conn = psycopg2.connect(conn_string)
cursor = conn.cursor()

reader = csv.reader(open('productcatalog.csv','rb'))

for row in reader:
    print row[1]

    statement = "INSERT INTO product_template (name,uom_id,uom_po_id,categ_id,standard_price,list_price,supply_method,mes_type,procure_method,cost_method,type,sale_ok) VALUES \
    ('" + row[1] + "','" + (row[2]) + "','" + (row[3]) + "','" + (row[4]) + "'," + str(row[5]) + "," + str(row[5]) + ",'produce','fixed','make_to_stock','standard','product',True) RETURNING id"

    templateid = cursor.fetchone()[0]

    statement = "INSERT INTO product_product (product_tmpl_id,default_code,active,valuation) VALUES \
    (" + str(templateid) + ",'" + row[0] + "',True,'manual_periodic')"


But I receive the following error:

Traceback (most recent call last): File "pruebaupload.py", line 11, in <module> print row[1] IndexError: list index out of range

Any clues? Thanks...




| 5 4 7
Baarn, Netherlands
On 5/22/13, 11:39 AM

The error is about the script trying to access a value it cannot read. It looks like your field row[1] does not exist. Try to print row (without [1]) and see what it contains. It might be that your method gave an empty line, or just 1 item (and so row[0] is the only valid option).

As Denis states, it is quite dangerous to import data into the database this way. It is an option when you made your own tables, but for existing tables/models it is dangerous.


Bonnet Denis

--Bonnet Denis--
| 5 6 8
St avé, France
--Bonnet Denis--

CEO/ODOO expert at Talyes.in

Bonnet Denis
On 5/22/13, 6:05 AM

Why did you not use import function? If you write directly in database you can miss some workflow activity.

And how do you use the import function to import price lists? There are no expor option at this point...

Pretensa Ltda., Jesua
on 5/22/13, 2:14 PM

Jesua, if needed check the script I made at the answer at http://help.openerp.com/question/13542/create-multiple-fixed-price-pricelists/

on 5/23/13, 4:08 AM

Can't you use export function from tree/list view?

Bonnet Denis
on 5/23/13, 5:52 AM

Thanks a lot... I finally got the importing function to work.... and I will check out the pricelists script...

Pretensa Ltda., Jesua
on 5/23/13, 6:45 PM

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

0 follower(s)


Asked: 5/21/13, 7:37 PM
Seen: 3533 times
Last updated: 3/16/15, 8:10 AM