Odoo Help

Welcome!

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

0

How to execute python-script for importing products directly to postgresql

By
kannu
on 9/3/14, 11:48 AM 5,024 views

I Kept this python file as well as csv file in server-folder. But it's not importing products!

Python Script-

import csv
import psycopg2

conn_string = "dbname= 'toc' user='openerp' password='sigma@123'"

conn = psycopg2.connect(conn_string)
cursor = conn.cursor()

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

for row in reader:
    print row[1]
   
    statement = "INSERT INTO product_template (name,description) VALUES ('" +row[1]+"','" +(row[2])+"') 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()
   
   ?
               
   

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/3/14, 11:48 AM
Seen: 5024 times
Last updated: 3/16/15, 8:10 AM