2017-02-25 5 views
0

MSSQLからPython-Odooにデータをインポートしようとしています。私は以下のコードで1つのフィールドをインポートできます。これは動作しますが、名前以外のフィールドを取得したいと思います。MSSQLからPython

#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

'[ '記録'] [ 'recordbarcode']'ないのリストを望んでいましたか? –

+0

私はそれがバーコードフィールドを挿入することを望んでいたのか分かりません。私はテスト/学習しています – user2379186

+0

あなたにはフィールドがありません。これは2つの文字列と2つのリストです –

答えて

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} 

または2つの辞書だと思いますどのような

[record, recordbarcode] 
+1

{name ':name、' barcode ':barcode}ありがとうございました。 – user2379186

+0

レコードがすでに存在する場合は行を更新したい場合は、バーコードに基づいてレコードが存在しない場合は新しいレコードを作成します。私はresultset = OdooApi.execute_kw(データベース、uid、pwd、 'product.template'、 'update'、[record])を試しました – user2379186

+0

新しい質問がある場合は、新しい投稿を作成してください –