Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
2005 Widoki

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


Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor

Thanks Savya Sachin for your support

Powiązane posty Odpowiedzi Widoki Czynność
1
maj 24
2139
2
cze 23
2222
1
maj 20
2379
1
maj 20
2860
2
sie 23
2829