'诠释'对于odoo 8,value不是函数返回

时间:2017-08-28 07:50:57

标签: python xml python-2.7 odoo-8

我想在屏幕上显示记录总数。为此,我已经为函数编写了查询语言,并通过从python代码打印该值,在Ubuntu 14.04命令行界面上得到了所需的结果。但是当我在函数中返回此值时,它会显示错误弹出消息" TypeError:' int'对象不可迭代"。所以,任何人都可以为我提供适当的解决方案。我的函数和字段的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

1 个答案:

答案 0 :(得分:1)

您需要返回其键为id的dict,例如:

count = 1
with open('My.txt') as f:
    for item in f.readlines():
        tmp = open(str(count) + '.txt', 'w')
        tmp.write(item)
        tmp.close()
        count += 1

查看Function field