I want to get total amount hours of specific timesheet lines
I get an error like:
Error:
Odoo Server Error
Traceback (most recent call last):
File "/home/odoo/src/odoo/odoo/api.py", line 1032, in get
value = self._data[field][record.id][key]
KeyError: <odoo.api.Environment object at 0x7f97740c9ef0>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/odoo/src/odoo/odoo/fields.py", line 970, in __get__
value = record.env.cache.get(record, self)
File "/home/odoo/src/odoo/odoo/api.py", line 1034, in get
raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: ('hr.payslip(1,).api_timesheet_hours', None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/odoo/src/odoo/odoo/http.py", line 654, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/odoo/src/odoo/odoo/http.py", line 312, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/home/odoo/src/odoo/odoo/tools/pycompat.py", line 87, in reraise
raise value
File "/home/odoo/src/odoo/odoo/http.py", line 696, in dispatch
result = self._call_function(**self.params)
File "/home/odoo/src/odoo/odoo/http.py", line 344, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/odoo/src/odoo/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "/home/odoo/src/odoo/odoo/http.py", line 337, in checked_call
result = self.endpoint(*a, **kw)
File "/home/odoo/src/odoo/odoo/http.py", line 939, in __call__
return self.method(*args, **kw)
File "/home/odoo/src/odoo/odoo/http.py", line 517, in response_wrap
response = f(*args, **kw)
File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 962, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 954, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/odoo/src/odoo/odoo/api.py", line 749, in call_kw
return _call_kw_multi(method, model, args, kwargs)
File "/home/odoo/src/odoo/odoo/api.py", line 736, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/home/odoo/src/odoo/odoo/models.py", line 2770, in read
values[name] = field.convert_to_read(record[name], record, use_name_get)
File "/home/odoo/src/odoo/odoo/models.py", line 5049, in __getitem__
return self._fields[key].__get__(self, type(self))
File "/home/odoo/src/odoo/odoo/fields.py", line 974, in __get__
self.determine_value(record)
File "/home/odoo/src/odoo/odoo/fields.py", line 1085, in determine_value
self.compute_value(recs)
File "/home/odoo/src/odoo/odoo/fields.py", line 1041, in compute_value
self._compute_value(records)
File "/home/odoo/src/odoo/odoo/fields.py", line 1032, in _compute_value
getattr(records, self.compute)()
File "/home/odoo/src/user/payroll_timesheet/models/hr_payslip.py", line 25, in _api_timesheets
self.api_timesheet_hours = float(sum(map(api_timesheets.mapped('unit_amount'))))
TypeError: map() must have at least two arguments.
this is my python code:
api_timesheet_hours = fields.Float(compute="_api_timesheets")
@api.multi
def _api_timesheets( self ):
all_timesheets = self.env["account.analytic.line"].search(
[('employee_id', '=', self.employee_id.name), ('date', '>=', self.date_from), ('date', '<=', self.date_to),
('validated', '=', True)])
api_timesheets = all_timesheets.search([('account_id', '=', "API")])
self.api_timesheet_hours = float(sum(map(api_timesheets.mapped('unit_amount'))))