Toll Free: (855) 881-7165

LiveZilla Live Chat Software             

OpenERP 7.0 Videos - Install, Configure, and Implement OpenERP

21

In the previous article and video we demonstrated how to import data into OpenERP using the XML-RPC method. There are some advantages of using XML-PRC method of importing data. It works through the ORM (Object Relationship Model) and has better integrity protection of your data. Unfortunately going through XML-RPC is very slow. Even on very fast computers each record insert can take as much as a full second. This is not a big deal if you are only importing a few dozen records. If however you are importing thousands of records or perhaps millions of records the XML-RPC method is simply too slow to be an adequate solution.

In the video below we will import data into OpenERP by inserting directly into the PostGRES database. The performance is well over 100 times faster. The downside is that you will have to be more responsible for maintaining the data integrity in your script. So make sure you test well and if you are ever running an import script on a production system make sure you backup everything. You will also want to turn off the OpenERP server (leave the PostGRES server running of course) just to make sure you don't have any unforeseen issues.


The script used in the video is provided below.



OpenERP 7 - Example Python Script for importing data directly into PostGRES database


import csv
import psycopg2

conn_string = "dbname='db2' user='openpg' password='openpgpwd'"

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

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

for row in reader:
    print row[1]

    statement = "INSERT INTO product_template (name,standard_price,list_price,mes_type,uom_id,uom_po_id," \
    "type,procure_method,cost_method,categ_id,supply_method,sale_ok) VALUES ('" + row[1] + "'," \
    + str(row[2]) + "," + str(row[2]) + ",'fixed',1,1,'product','make_to_stock','standard',1,'buy',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()

Post Rating

Comments

There are currently no comments, be the first to post one.

Post Comment

Name (required)

Email (required)

Website

CAPTCHA image
Enter the code shown above: