'Int' 值在 odoo 8 的函数中不是 return

'Int' value is not return in function for odoo 8

我想在屏幕上显示记录总数。为此,我为函数编写了查询语言,并通过从 python 代码打印该值,在 Ubuntu 14.04 命令行屏幕上获得了期望的结果。但是当我在函数中 return 这个值时,它会显示错误弹出消息 "TypeError: 'int' object is not iterable"。所以,任何人都可以给我适当的解决方案来解决这个问题。我的 python 函数和字段代码如下。

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

你需要return一个字典,它的键是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