Skip to Content
Menu
This question has been flagged
1 Reply
1990 Views

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
Discard
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
Discard
Author

Thanks Savya Sachin for your support

Related Posts Replies Views Activity
1
May 24
2122
2
Jun 23
2205
1
May 20
2373
1
May 20
2849
2
Aug 23
2809