MSSQL到Python
我正在尝试将数据从MSSQL导入Python-Odoo安装。我可以用下面的代码导入一个字段。这是可行的,但我想检索除名称以外的其他字段MSSQL到Python,python,python-2.7,openerp,Python,Python 2.7,Openerp,我正在尝试将数据从MSSQL导入Python-Odoo安装。我可以用下面的代码导入一个字段。这是可行的,但我想检索除名称以外的其他字段 #Retrieve data through recordset RecCount =rs.RecordCount print RecCount while not rs.EOF: # print rs.Fields.item('Description').value # print rs.Fields.item('Price').val
#Retrieve data through recordset
RecCount =rs.RecordCount
print RecCount
while not rs.EOF:
# print rs.Fields.item('Description').value
# print rs.Fields.item('Price').value
name = rs.Fields.item('Description').value
record = {'name' : name}
filter = [[['name' ,'=', name]]]
product_id = OdooApi.execute_kw(database, uid, pwd, 'product.template', 'search', filter)
if not product_id:
print " Create - " + name
resultset = OdooApi.execute_kw(database, uid, pwd, 'product.template', 'create', [record])
else:
print "Already in table - " + name
rs.Move(1)
我想导入其他字段,如条形码字段。下面是我尝试过的,但我得到了一个错误
#Retrieve data through recordset
RecCount =rs.RecordCount
print RecCount
while not rs.EOF:
# print rs.Fields.item('Description').value
# print rs.Fields.item('Price').value
name = rs.Fields.item('Description').value
barcode = rs.Fields.item('ItemLookupCode').value
record = {'name' : name}
recordbarcode = {'barcode' : barcode}
filter = [[['barcode' ,'=', barcode]]]
product_id = OdooApi.execute_kw(database, uid, pwd, 'product.template', 'search', filter)
if not product_id:
print " Create - " + barcode
resultset = OdooApi.execute_kw(database, uid, pwd, 'product.template', 'create', ['record']['recordbarcode'] )
else:
print "Already in table - " + barcode
rs.Move(1)
我在上面代码中得到的错误是
Traceback (most recent call last):
File "importdataorg.py", line 58, in <module>
resultset = OdooApi.execute_kw(database, uid, pwd, 'product.template', 'create', ['record']['recordbarcode'] )
TypeError: list indices must be integers, not str
回溯(最近一次呼叫最后一次):
文件“importdataorg.py”,第58行,在
resultset=OdooApi.execute_kw(数据库、uid、pwd、“产品模板”、“创建”、“记录”][“记录条形码”])
TypeError:列表索引必须是整数,而不是str
我不确定您的错误是否与您正在使用的任何工具有关
['record']['recordbarcode']
不是有效的Python
只需在REPL中单独运行它,列表索引必须是整数,而不是str
您想使用这些变量吗
record = {'name' : name}
recordbarcode = {'barcode' : barcode}
如果是这样,record['name']
是有效的,但实际上这只是已经可用的name
变量
也许你想要这本字典
{'name' : name, 'barcode' : barcode}
或者两本字典的列表
[record, recordbarcode]
你认为
['record']['recordbarcode']
有什么作用?我不知道我希望它能插入条形码字段。我正在测试/学习您在那里没有字段。这是两个字符串和两个列表如果我想在记录已经存在时更新一行,或者根据条形码创建一个新的记录(如果它还不存在)。我试过resultset=OdooApi.execute_kw(数据库、uid、pwd、'product.template'、'update'、[record])如果你有新问题,请创建一个新帖子