小编Tim*_*ung的帖子

如何编写使用OpenERP ORM直接上传到Postgres数据库的Python脚本

我需要在Python中编写一个"独立"脚本,仅使用OpenERP的ORM模块将销售税上传到数据库中的account_tax表.我想做的是像下面的伪代码.

有人可以提供以下更多详细信息:1)我需要设置什么样的sys.path 2)在导入"account"模块之前我需要导入哪些模块.目前,当我导入"帐户"模块时,我收到以下错误:AssertionError:报告"report.custom"已经存在!3)获取数据库光标的正确方法是什么.在下面的代码中,我只是直接调用psycopg2来获取游标.

如果这种方法不起作用,除了编写XML文件以从OpenERP应用程序本身加载数据之外,是否有人可以提出替代方法.此过程需要在标准OpenERP应用程序之外运行.

PSEUDO代码:

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.
Run Code Online (Sandbox Code Playgroud)

openerp

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

openerp ×1