2017-08-28 7 views
0

画面上の総レコード数を表示したい。このために私は関数のためのクエリ言語を書いていると私は、Pythonコードからその値を印刷することによってUbuntuの14.04コマンドライン画面で欲望の結果を得る。しかし、この値を関数で返すと、エラーポップアップメッセージ "TypeError: 'int'オブジェクトが反復可能でないことが表示されます。ですから誰でも私にこの問題の適切な解決策を与えることができます。関数とフィールドの私のPythonコードは以下の通りです。odooの関数で 'Int'値が関数で返されない8

Pythonコード:

def get_count(self, cr, uid, ids, sequence, arg, context=None): 
    cr.execute('SELECT count(*) from sun_helpdesk') 
    u_data = cr.fetchall() 
    print "cr:", u_data 
    print "res:",int(u_data[0][0]) 
    return int(u_data[0][0]) 

_columns = { 
    'sequence': fields.function(get_count, method=True, string='Total Tickets', type='integer'), 
} 

XMLコード:XMLで このフィールドは単に添加。 Ubuntuの画面上

結果は次のとおりです。

cr: [(101L,)] 

res: 101 

new_values = dict(values) 

TypeError: 'int' object is not iterable 
+0

何を見てみましょう'new_values = dict(values)'の 'values'ですか? – quamrana

+0

'int(u_data [0] [0])'から 'int'を削除し、それをテストしてください。私はあなたが得るものはタプルであり、それをintにしようとしていると思います。 – 0decimal0

答えて

1

あなたは、たとえば、そのキーはIDが辞書を返す必要があります。

def get_count(self, cr, uid, ids, sequence, arg, context=None): 

    res = {} 

    cr.execute('SELECT count(*) from sun_helpdesk') 
    u_data = cr.fetchall() 
    print "cr:", u_data 
    print "res:",int(u_data[0][0]) 

    #res[id] must be set to False and not to None because of XML:RPC 
    # "cannot marshal None unless allow_none is enabled" 
    res[ids[0]] = int(u_data[0][0]) if ids else False 
    return res 

Function field

+0

ありがとうございました...!それは働いている。 –