我正在尝试将数据从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').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
答案 0 :(得分:0)
我不确定您的错误与您正在使用的任何工具有关。
['record']['recordbarcode']
不是有效的Python。
只需在REPL中运行,list indices must be integers, not str
您想使用这些变量吗?
record = {'name' : name}
recordbarcode = {'barcode' : barcode}
如果是,record['name']
有效,但这实际上只是已有的name
变量。
也许你想要这本词典
{'name' : name, 'barcode' : barcode}
或两个词典的列表
[record, recordbarcode]