我需要在 Python 中编写一个“独立”脚本,仅使用 OpenERP 的 ORM 模块将销售税上传到数据库中的 account_tax 表。我想做的是类似于下面的伪代码。
有人可以向我提供有关以下内容的更多详细信息:1)我需要设置什么 sys.path 2)在导入“帐户”模块之前我需要导入哪些模块。目前,当我导入“帐户”模块时,我收到以下错误:AssertionError:报告“report.custom”已经存在!3)获取我的数据库游标的正确方法是什么。在下面的代码中,我只是直接调用 psycopg2 来获取游标。
如果这种方法行不通,除了编写 XML 文件来从 OpenERP 应用程序本身加载数据之外,任何人都可以提出替代方法。这个过程需要在标准 OpenERP 应用程序之外运行。
伪代码:
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.