gpt4 book ai didi

python - openerp错误AttributeError : 'int' object has no attribute 'iteritems'

转载 作者:行者123 更新时间:2023-12-01 05:17:01 33 4
gpt4 key购买 nike

我试图在我的代码中使用多参数,然后出现了这个错误,我已经尝试了一切,但仍然无法纠正这个错误。请告诉我如何纠正这个错误。我的代码如下

class client_client(osv.osv):
def totalsum(self, cr, uid, ids, field_name, args, context=None):
tsum = {}
for dx in self.browse(cr, uid, ids, context=context):
tsum[dx.id] = (dx.cp1val + dx.cp2val)
print tsum
return tsum

def totalsum_val(self, cr, uid, ids, context=None):
tqw = {}

for cl in self.browse(cr, uid, ids, context=None):
tqw[cl.id] = (cl.cp1val + cl.cp2val + 2)
return tqw.keys()


_name = 'client.client'

_columns = {
'total': fields.function(totalsum, type='integer', string='Total', help="Total sum",
store={'client.client': (totalsum_val, ['cp1val', 'cp2val'], 10)}, multi='calc'),
'total2': fields.function(totalsum, type='integer', string='2nd total',
store={'client.client': (totalsum_val, ['cp1val', 'cp2val'], 10)}, multi='calc'),
'total3': fields.function(totalsum, type='integer', string='3rd total',
store={'client.client': (totalsum_val, ['cp1val', 'cp2val'], 10)}, multi='calc'),
'cp1val': fields.integer('NO 1', size=45, help="First no to be added", required=True),
'cp2val': fields.integer('NO 2', size=45, help="Second no to be added", required=True),
}

_defaults = {
}

基本上我现在想做的是在totalsum()函数中添加两个no的cp1val,cp2val,然后使用multi和store参数我想在totalsum_val函数中添加相同的cp1val,cp2val与整数2,但是我'我没有得到它,只有totalsum函数正确执行,并且我在total字段中得到它的输出。请帮我解决这个问题

这是日志

Server Traceback (most recent call last):
File "/home/subash/Openerp_11_12_13/web/addons/web/session.py", line 89, in send
return openerp.netsvc.dispatch_rpc(service_name, method, args)
File "/home/subash/Openerp_11_12_13/server/openerp/netsvc.py", line 292, in dispatch_rpc
result = ExportService.getService(service_name).dispatch(method, params)
File "/home/subash/Openerp_11_12_13/server/openerp/service/web_services.py", line 626, in dispatch
res = fn(db, uid, *params)
File "/home/subash/Openerp_11_12_13/server/openerp/osv/osv.py", line 188, in execute_kw
return self.execute(db, uid, obj, method, *args, **kw or {})
File "/home/subash/Openerp_11_12_13/server/openerp/osv/osv.py", line 131, in wrapper
return f(self, dbname, *args, **kwargs)
File "/home/subash/Openerp_11_12_13/server/openerp/osv/osv.py", line 197, in execute
res = self.execute_cr(cr, uid, obj, method, *args, **kw)
File "/home/subash/Openerp_11_12_13/server/openerp/osv/osv.py", line 185, in execute_cr
return getattr(object, method)(cr, uid, *args, **kw)
File "/home/subash/Openerp_11_12_13/server/openerp/osv/orm.py", line 4500, in create
self.pool.get(object)._store_set_values(cr, user, ids, fields2, context)
File "/home/subash/Openerp_11_12_13/server/openerp/osv/orm.py", line 4627, in _store_set_values
result = self._columns[val[0]].get(cr, self, ids, val, SUPERUSER_ID, context=context)
File "/home/subash/Openerp_11_12_13/server/openerp/osv/fields.py", line 1144, in get
for field, value in result[id].iteritems():
AttributeError: 'int' object has no attribute 'iteritems'

最佳答案

对于 multi,您必须将该函数的结果字典更改为以下形式:

{'id1':{
'field1':value,
'field2':value,
'field3':value,
},
'id2':{and so on...
}

因此,对于您的示例,您的函数必须如下所示:

def totalsum(self,cr,uid,ids,field_name,args,context=None):
tsum={}
for dx in self.browse(cr,uid,ids,context=context):
tsum[dx.id]={
'total':#value here,
'total2':#value here,
'total3':#value here,
}
print tsum
return tsum

关于python - openerp错误AttributeError : 'int' object has no attribute 'iteritems' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22983771/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com