我试图在我的代码中使用多参数然后出现这个错误我已经尝试了一切我仍然无法纠正这个错误。请告诉我如何纠正这个问题。我的代码如下
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函数正确执行,我在总字段中得到它的输出。请帮帮我
这是日志
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'
答案 0 :(得分:2)
对于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