greywind
greywind

Reputation: 107

openerp error AttributeError: 'int' object has no attribute 'iteritems'

I was trying to use multi parameter in my code then this error came up I have tried everything still I am not able to rectify this error .Pls tell me how can I correct this,. my code is as follows

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 = {
    }

Basically What I want to do right now is to add two no's cp1val,cp2val in totalsum() function ,then using multi and store parameter I want to add the same cp1val,cp2val with integer 2 in totalsum_val function ,but I'm not getting it only the totalsum function is executing correctly and I'm getting its output in total field. Please help me on this

Here is log

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'

Upvotes: 1

Views: 3487

Answers (1)

CZoellner
CZoellner

Reputation: 14768

for multi you have to change your result dictionary of that function into following form:

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

so for your example your function have to look like:

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

Upvotes: 2

Related Questions