Skip to Content
Menu
This question has been flagged

Hello

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") 

@api.multi
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}
geh_since_last_visit_ids_obj.create(vals)


pass


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')


Avatar
Discard

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

Author

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

Related Posts Replies Views Activity
1
Mar 15
4071
0
Aug 19
2491
1
Dec 15
5138
1
Mar 15
3100
1
Aug 22
6317