Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
2052 Представления

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(),
})


Аватар
Отменить
Лучший ответ

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

Аватар
Отменить
Автор

Thanks Savya Sachin for your support

Related Posts Ответы Просмотры Активность
1
мая 24
2227
2
июн. 23
2297
1
мая 20
2427
1
мая 20
2905
2
авг. 23
2900