Skip to Content
Menu
This question has been flagged
2 Replies
2455 Views

Hello, I am using odoo 13.

Employees in the system can check-in and check out multiple times per day. I want to get the first check and the last check out for a specific employee every day.

this is is my code for the first check in, but it got first check-in not for specific day but for the whole time

def get_first_check_in_time(self):
first_sign_in = ''
for emp in self:
attn_ids = self.env['hr.attendance'].search([('employee_id', '=', emp.id)])
if attn_ids:
for a in attn_ids:
if not emp.first_sign_in:
emp.first_sign_in = a.check_in
else:
first_sign_in = min(emp.first_sign_in, a.check_in)
emp.first_sign_in = first_sign_in
else:
emp.first_sign_in = False

Avatar
Discard
Author Best Answer

I have added your code and it gives me an error that is (unresolved reference context_today)


Avatar
Discard
Best Answer

Hi,

You can additional domain when you search the 'attn_ids' from the model 'hr,attendance' so that it returns only the data that has check in date greater than current date starting time.

attn_ids = self.env['hr.attendance'].search( [ ('employee_id', '=', emp.id), ('check_in, '>=', datetime.datetime.combine(context_today(), datetime.time(0,0,0)))])

Regards

Avatar
Discard
Related Posts Replies Views Activity
2
Nov 22
13995
4
Jan 24
11223