Skip to Content
Menú
This question has been flagged
1 Respondre
1992 Vistes

When an employee forget to checkout  attendance after 10 hours attendance should be check out automatically in odoo .  also added one selection field it should be filled when 10 hours completed and auto checkout.

class HrAttendance(models.Model):
_inherit = 'hr.attendance'



actives_id = fields.Boolean(compute='_compute_forget_logout',store=True)
att_forget_logout = fields.Selection([('forget_logout', 'Forget Logout')], string='Forget Logout')

@api.depends('check_in', 'check_out')
def _compute_forget_logout(self):
for rec in self:
check_in_time = fields.Datetime.from_string(rec.check_in)
print(check_in_time, '.............................check_in time')
logout_time = check_in_time + timedelta(hours=10)
if datetime.now() > logout_time:
rec.actives_id = True
rec.att_forget_logout = 'forget_logout'
else:
rec.actives_id = False
rec.write({
'check_out': fields.Datetime.now(),
})


Avatar
Descartar
Best Answer

Hi,

Instead, you can try creating a scheduled action to execute the following code,

@api.model
def auto_checkout_attendance(self):
attendance_records = self.env['hr.attendance'].search([('check_out', '=', False)])
for attendance in attendance_records:
check_in_time = fields.Datetime.from_string(attendance.check_in)
logout_time = check_in_time + timedelta(hours=10)
if datetime.now() > logout_time:
attendance.write({
'check_out': fields.Datetime.now(),
'actives_id': True,
'att_forget_logout': 'forget_logout',
})

Thanks

Avatar
Descartar
Autor

Thanks Savya Sachin for your support

Related Posts Respostes Vistes Activitat
1
de maig 24
2122
2
de juny 23
2205
1
de maig 20
2373
1
de maig 20
2849
2
d’ag. 23
2809