1

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'
4
  • just simply return tqw, may be issue of keys(). Commented Apr 10, 2014 at 10:19
  • I have tried it too ,It was of no use Commented Apr 10, 2014 at 10:23
  • in which function do you have problem ? can you paste sever log? Commented Apr 10, 2014 at 10:34
  • actually totalsum function is working correctly ,the problem is with totalsum_val function where I'm using multi and store parameter .. Commented Apr 10, 2014 at 10:40

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

2 Comments

Does that mean whenever we use multi , we have to seperately assign values to it .? Why is that?
if you use multi, you have to do it that way. oh, i didn't see, that you're using your second function as multi, too. just change it the way the first function (totalsum()) was changed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.