How to write a Python script that uses the OpenERP ORM to directly upload to Postgres Database

Viewed 14384

I need to write a "standalone" script in Python to upload sales taxes to the account_tax table in the database using ONLY the ORM module of OpenERP. What I would like to do is something like the pseudo code below.

Can someone provide me a more details on the following: 1) what sys.path's do I need to set 2) what modules do I need to import before importing the "account" module. Currently when I import the "account" module I get the following error: AssertionError: The report "report.custom" already exists! 3) What is the proper way to get my database cursor. In the code below I am simply calling psycopg2 directly to get a cursor.

If this approach cannot work, can anyone suggest an alternative approach other than writing XML files to load the data from the OpenERP application itself. This process needs to run outside of the the standard OpenERP application.

PSEUDO CODE:

import sys
# set Python paths to access openerp modules
sys.path.append("./openerp")
sys.path.append("./openerp/addons")

# import OpenERP 
import openerp

# import the account addon modules that contains the tables 
# to be populated.
import account

# define connection string
conn_string2 = "dbname='test2' user='xyz' password='password'"

# get a db connection
conn = psycopg2.connect(conn_string2)

# conn.cursor() will return a cursor object
cursor = conn.cursor()

# and finally use the ORM to insert data into table.
8 Answers
Related