Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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 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 + "','" + (row) + "','" + (row) + "','" + (row) + "'," + str(row) + "," + str(row) + ",'produce','fixed','make_to_stock','standard','product',True) RETURNING id" cursor.execute(statement) conn.commit() templateid = cursor.fetchone() statement = "INSERT INTO product_product (product_tmpl_id,default_code,active,valuation) VALUES \ (" + str(templateid) + ",'" + row + "',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 IndexError: list index out of range
Any clues? Thanks...
The error is about the script trying to access a value it cannot read. It looks like your field row does not exist. Try to print row (without ) and see what it contains. It might be that your method gave an empty line, or just 1 item (and so row 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.
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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 5/21/13, 7:37 PM|
|Seen: 3138 times|
|Last updated: 3/16/15, 8:10 AM|