Odoo Help


Function field result error record[f] = res2[record['id']] KeyError: 9

on 5/21/13, 6:05 PM 1,662 views

Hi All!

I have this function field:

'copy_to_stock': fields.function(copy_data,method=True,type='boolean',store = False),

I call it in xml by:

 <field name="copy_to_stock" invisible="1"/>

I have this code:

def copy_data(self,cr,uid,ids,y,z,context=None):
    move = self.pool.get('stock.move')      
    product_obj = self.pool.get('product.product')
    result = {} 
    for line in self.browse(cr, uid, ids, context=context):
        result[line.id] = True
        if line.stck_mov_id == 0:
            product_ids = line.pname.id
            products = product_obj.browse(cr, uid, product_ids, context=context)
            prod_name = products.name_template
            now = datetime.datetime.now()
            move_obj_id = move.create(cr,uid,{'product_uom' : line.product_uom.id,
                            'date_expected' : now,
                            'date' : now,
                            'product_qty' : line.product_qty,
                            'location_id' : line.location_id.id,
                            'name' : prod_name,
                            'product_id' : line.pname.id,
                            'company_id' : 1,
                            'location_dest_id': line.location_dest_id.id,
                            'state' : 'done'})  

            if move_obj_id:
                self.write(cr, uid, [line.id], {'stck_mov_id': move_obj_id}, context=context)
            return result

and I have this result:

Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_20121011_233149-py2.7.egg/openerp/osv/osv.py", line 121, in wrapper return f(self, dbname, args, *kwargs) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_20121011_233149-py2.7.egg/openerp/osv/osv.py", line 176, in execute res = self.execute_cr(cr, uid, obj, method, args, *kw) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_20121011_233149-py2.7.egg/openerp/osv/osv.py", line 164, in execute_cr return getattr(object, method)(cr, uid, args, *kw) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_20121011_233149-py2.7.egg/openerp/osv/orm.py", line 3416, in read result = self._read_flat(cr, user, select, fields, context, load) File "/usr/local/lib/python2.7/dist-packages/openerp-6.1_20121011_233149-py2.7.egg/openerp/osv/orm.py", line 3542, in _read_flat record[f] = res2[record['id']] KeyError: 9

I try to do a lot of things, but I do not understand what is the root cause. I try to make a lot of things with the result of the function, but It takes me into deep in the madness....

I do not want the result, I wanna forget it:-) if this is Null or nill is ok for me, sure the system may need it, but w**???? :-)

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 5/21/13, 6:05 PM
Seen: 1662 times
Last updated: 3/16/15, 8:10 AM