Odoo Help


record[f] = res2[record['id']] KeyError: 1

eman ibrahim
on 4/14/14, 12:36 PM 3,568 views

i have create a python object

class insurance_issuance(osv.osv):

_name = 'insurance.issuance'
_description = 'Insurance Issuance'

def insurance_update(self, cr, uid, ids, insurance_exp, emp_name, dep_name, context=None):
    d = self.pool.get('hr.emp.dependents').browse(cr, uid, ids, context=None)
    exp = d[0]
    if exp.insurance_exp_date==date.today():
        return {'value': {'insurance_exp': exp.insurance_exp_date,'emp_name': exp.d.emp_line,'dep_name': exp.name}}
    return {'value': {}}

_columns = {
    'emp_name': fields.many2one('hr.employee', 'Employee', readonly=False),
    'dep_name': fields.char('Name', size=50, readonly=False, required=True),
    'insurance_exp': fields.function(insurance_update, method = True, type = 'date', String='Insurance Expire Date')



an error appear is

Traceback (most recent call last): File "/home/eman/Desktop/openerp-7.0-20140407-232745/openerp/netsvc.py", line 296, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "/home/eman/Desktop/openerp-7.0-20140407-232745/openerp/service/web_services.py", line 626, in dispatch res = fn(db, uid, params) File "/home/eman/Desktop/openerp-7.0-20140407-232745/openerp/osv/osv.py", line 190, in execute_kw return self.execute(db, uid, obj, method, *args, *kw or {}) File "/home/eman/Desktop/openerp-7.0-20140407-232745/openerp/osv/osv.py", line 132, in wrapper return f(self, dbname, args, *kwargs) File "/home/eman/Desktop/openerp-7.0-20140407-232745/openerp/osv/osv.py", line 199, in execute res = self.execute_cr(cr, uid, obj, method, args, *kw) File "/home/eman/Desktop/openerp-7.0-20140407-232745/openerp/osv/osv.py", line 187, in execute_cr return getattr(object, method)(cr, uid, args, *kw) File "/home/eman/Desktop/openerp-7.0-20140407-232745/openerp/osv/orm.py", line 3679, in read result = self._read_flat(cr, user, select, fields, context, load) File "/home/eman/Desktop/openerp-7.0-20140407-232745/openerp/osv/orm.py", line 3803, in _read_flat record[f] = res2[record['id']] KeyError: 1

how i can fix that

Roc cheng
On 4/25/14, 1:23 AM

Hi,It looks like you defined the wrong fuction for the fucuction_field:

 return {'value': {'insurance_exp': exp.insurance_exp_date,'emp_name': exp.d.emp_line,'dep_name': exp.name}}

update another field by one fuction,you need use 'mutil': multi set, the field_name is replaced by field_names: a list of the field names that should be computed. Each value in the returned dictionary must then be a dictionary mapping field names to values. example:

        _columns['name'] = fields.function(compute_person_data, type='char',\
                                           size=50, multi='person_data')
        _columns[''age'] = fields.function(compute_person_data, type='integer',\

        # when called with ``ids=[1,2,3]``, ``compute_person_data`` could return:
            1: {'name': 'Bob', 'age': 23},
            2: {'name': 'Sally', 'age': 19},
            3: {'name': 'unknown', 'age': False}

The another way,in your function call the 'wirte' method update the 'emp_name' and 'dep_name',but the retuen: mapping of ids to computed values,just update the function_field... hope it will help you


Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 4/24/14, 4:02 PM

Do a browse() and assign value to each ID. res [each id ] = some value.

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: 4/14/14, 12:36 PM
Seen: 3568 times
Last updated: 3/16/15, 8:10 AM