This question has been flagged
1 Reply
4025 Views

Hi forum, i get this error:

raceback (most recent call last):

File "/app/odoo/fields.py", line 948, in __get__

value = record.env.cache.get(record, self)

File "/app/odoo/api.py", line 967, in get

value = self._data[key][field][record._ids[0]]

KeyError: 15


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

File "/app/odoo/http.py", line 657, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "/app/odoo/http.py", line 312, in _handle_exception

raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])

File "/app/odoo/tools/pycompat.py", line 87, in reraise

raise value

File "/app/odoo/http.py", line 699, in dispatch

result = self._call_function(**self.params)

File "/app/odoo/http.py", line 344, in _call_function

return checked_call(self.db, *args, **kwargs)

File "/app/odoo/service/model.py", line 97, in wrapper

return f(dbname, *args, **kwargs)

File "/app/odoo/http.py", line 337, in checked_call

result = self.endpoint(*a, **kw)

File "/app/extra_addons/smile_perf_analyzer/models/http.py", line 25, in __call__

res = profile(native_call)(self, *args, **kwargs)

File "/app/extra_addons/smile_perf_analyzer/tools/decorators.py", line 26, in wrapper

return func(*args, **kwargs)

File "/app/odoo/http.py", line 943, in __call__

return self.method(*args, **kw)

File "/app/odoo/http.py", line 517, in response_wrap

response = f(*args, **kw)

File "/app/addons/web/controllers/main.py", line 934, in call_kw

return self._call_kw(model, method, args, kwargs)

File "/app/addons/web/controllers/main.py", line 926, in _call_kw

return call_kw(request.env[model], method, args, kwargs)

File "/app/odoo/api.py", line 687, in call_kw

return call_kw_model(method, model, args, kwargs)

File "/app/odoo/api.py", line 672, in call_kw_model

result = method(recs, *args, **kwargs)

File "/app/odoo/models.py", line 3409, in create

record = self.browse(self._create(old_vals))

File "/app/odoo/models.py", line 3566, in _create

self.recompute()

File "/app/extra_addons/smile_perf_analyzer/models/models.py", line 25, in recompute

_recompute(self, field, recs)

File "/app/extra_addons/smile_perf_analyzer/models/models.py", line 41, in _recompute

vals = {n: rec[n] for n in ns}

File "/app/extra_addons/smile_perf_analyzer/models/models.py", line 41, in

vals = {n: rec[n] for n in ns}

File "/app/odoo/models.py", line 4803, in __getitem__

return self._fields[key].__get__(self, type(self))

File "/app/odoo/fields.py", line 952, in __get__

self.determine_value(record)

File "/app/odoo/fields.py", line 1041, in determine_value

self.compute_value(recs)

File "/app/odoo/fields.py", line 1019, in compute_value

self._compute_value(records)

File "/app/odoo/fields.py", line 1010, in _compute_value

getattr(records, self.compute)()

File "/app/extra_addons/models/hr_attendance_sheet.py", line 201, in _compute_delegation_info

record.count_delegation_internal = self.env['hr.delegation'].search_count([('attendance_sheet_id', '=', self.id), ('delegation_type', '=', 'internal'), ('with_breakfast', '=', False)])

File "/app/odoo/fields.py", line 2564, in __get__

raise ValueError("Expected singleton: %s" % record)

ValueError: Expected singleton: hr.attendance.sheet(15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34)


The compute method who get this error:


@api.multi
@api.depends('delegation_ids', 'exchange_rate_id', 'exchange_rate_amount', 'da_delegation_internal', 'da_delegation_internal_breakfast', 'da_delegation_external', 'da_delegation_external_breakfast')
def _compute_delegation_info(self):
for record in self:
record.count_delegation_internal = self.env['hr.delegation'].search_count([('attendance_sheet_id', '=', self.id), ('delegation_type', '=', 'internal'), ('with_breakfast', '=', False)])
record.count_delegation_internal_breakfast = self.env['hr.delegation'].search_count([('attendance_sheet_id', '=', self.id), ('delegation_type', '=', 'internal'), ('with_breakfast', '=', True)])
record.count_delegation_external = self.env['hr.delegation'].search_count([('attendance_sheet_id', '=', self.id), ('delegation_type', '=', 'external'), ('with_breakfast', '=', False)])
record.count_delegation_external_breakfast = self.env['hr.delegation'].search_count([('attendance_sheet_id', '=', self.id), ('delegation_type', '=', 'external'), ('with_breakfast', '=', True)])
What can i do wrong?
Avatar
Discard
Author

Hi Jack Dane,

Thank you very much for your help, the code works, i really appreciate that!

Author

I try to mark your answer as the correct answer, but I get a 403 - Forbidden error. I contacted Odoo about this, anyway thanks again!

No Problem Steven, happy to help.

Best Answer

Hi Steven,

I imagine the issue is due to you using self.id instead of record.id in your search_count function, for loop, defines "record" as the individual record and "self" as the record set.

self.env['hr.delegation'].search_count([('attendance_sheet_id', '=', record.id), ('delegation_type', '=', 'internal'), ('with_breakfast', '=', False)])

Let me know if this works,

Avatar
Discard