Odoo Help


keyerror : 1 in a create with many2one in compute

Jean-Baptiste Bernard
on 6/26/15, 9:39 AM 1,284 views


I have a keyerror : 1 with my code and i don't undertand why?

 geh_since_last_visit_ids = fields.One2many('alde.employee.geh','employee_id', compute="_get_geh") 

def _get_geh(self):
timesheet_obj = self.env['alde.timesheet']
geh_obj = self.env['alde.geh']
_logger.error('Mon employee %s', self.id)
geh_since_last_visit_ids_obj = self.geh_since_last_visit_ids
vals ={}
time_geh = defaultdict(lambda: 0.0)

if self.last_medical_visit :
timesheet_ids = timesheet_obj.search([('employee_id','=', self.id), ('date','>=',self.last_medical_visit)])
else :
timesheet_ids = timesheet_obj.search([('employee_id','=', self.id)])

for timesheet_id in timesheet_ids :
time_geh[timesheet_id.machine_id.geh_id.id] += timesheet_id.time_amount

for geh_id_int in time_geh :
geh_id = geh_obj.browse(geh_id_int)
_logger.error('Mon geh %s contient %s', geh_id.id, time_geh[geh_id_int])
vals = {'name' : geh_id.id}


class alde_employee_geh(models.Model):
_name = 'alde.employee.geh'

name = fields.Many2one('alde.geh')
total_time = fields.Float()
exposed = fields.Boolean()
employee_id = fields.Many2one('alde.employee')

Usually, you should use @api.one and @api.depends() on functional field. Try that one. If still you face error, please paste the traceback.

Serpent Consulting Services Pvt. Ltd.
on 6/26/15, 10:52 AM

File "/opt/odoo/odoo8.0-server/openerp/http.py", line 537, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/opt/odoo/odoo8.0-server/openerp/http.py", line 574, in dispatch result = self._call_function(**self.params) File "/opt/odoo/odoo8.0-server/openerp/http.py", line 310, in _call_function return checked_call(self.db, *args, **kwargs) File "/opt/odoo/odoo8.0-server/openerp/service/model.py", line 113, in wrapper return f(dbname, *args, **kwargs) File "/opt/odoo/odoo8.0-server/openerp/http.py", line 307, in checked_call return self.endpoint(*a, **kw) File "/opt/odoo/odoo8.0-server/openerp/http.py", line 803, in __call__ return self.method(*args, **kw) File "/opt/odoo/odoo8.0-server/openerp/http.py", line 403, in response_wrap response = f(*args, **kw) File "/opt/odoo/odoo8.0-server/addons/web/controllers/main.py", line 944, in call_kw return self._call_kw(model, method, args, kwargs) File "/opt/odoo/odoo8.0-server/addons/web/controllers/main.py", line 936, in _call_kw return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs) File "/opt/odoo/odoo8.0-server/openerp/api.py", line 241, in wrapper return old_api(self, *args, **kwargs) File "/opt/odoo/odoo8.0-server/openerp/models.py", line 3139, in read result = BaseModel.read(records, fields, load=load) File "/opt/odoo/odoo8.0-server/openerp/api.py", line 239, in wrapper return new_api(self, *args, **kwargs) File "/opt/odoo/odoo8.0-server/openerp/models.py", line 3185, in read values[name] = field.convert_to_read(record[name], use_name_get) File "/opt/odoo/odoo8.0-server/openerp/models.py", line 5571, in __getitem__ return self._fields[key].__get__(self, type(self)) File "/opt/odoo/odoo8.0-server/openerp/fields.py", line 823, in __get__ return record._cache[self] File "/opt/odoo/odoo8.0-server/openerp/models.py", line 5930, in __getitem__ value = self._recs.env.cache[field][self._recs.id] KeyError: 1

Aldébarande, Jean-Baptiste Bernard
on 6/30/15, 4:43 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

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

1 follower(s)


Asked: 6/26/15, 9:39 AM
Seen: 1284 times
Last updated: 6/30/15, 4:43 AM