Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
10841 Lượt xem

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"

    cursor.execute(statement)
    conn.commit()
    templateid = cursor.fetchone()[0]

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

    cursor.execute(statement)
    conn.commit()

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...

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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

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

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

Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 18
3466
1
thg 3 16
3393
1
thg 3 15
9040
1
thg 2 21
4609
3
thg 7 17
4813