[FIX] hr_attendance: restrict to compute worked hours without employee

This traceback raises when user not selected 'Employee' and only selecting
'Check In' and 'Check Out', while creating a new attendance.

To reproduce the issue:

1) Install hr_attendance
2) Open Attendance and create a new record
3) Give values to only 'Check In' and 'Check Out'

Error:  "AttributeError: 'bool' object has no attribute 'upper'" appears.

On '_compute_worked_hours' method calendar variable is getting value from
employee_id and that calendar timezone is used to get timezone.

https://github.com/odoo/odoo/blob/937d207028ab9bc1d3d332dc6dfe25f0de045026/addons/hr_attendance/models/hr_attendance.py#L50-L60

Therefore in the above use case, when triggering the compute method,
because of 'calendar' is depending on 'employee_id' and when
employee is not selected, it will leads to the above traceback.

Sentry-4274226351

closes odoo/odoo#126465

X-original-commit: 31491e40d2505c03d76e6c802435ad1dafa71c52
Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
althaf shaik
2023-06-27 09:29:30 +02:00
parent 100b3b22c1
commit 2fdefd0f21
+1 -1
View File
@@ -54,7 +54,7 @@ class HrAttendance(models.Model):
@api.depends('check_in', 'check_out')
def _compute_worked_hours(self):
for attendance in self:
if attendance.check_out and attendance.check_in:
if attendance.check_out and attendance.check_in and attendance.employee_id:
calendar = attendance._get_employee_calendar()
resource = attendance.employee_id.resource_id
tz = timezone(calendar.tz)