This question has been flagged
5 Replies
8284 Views

if an employee forget to checkout in odoo attendance python code for auto checkout in attendance odoo and write the checkout time as check in time.

Avatar
Discard
Author

yes i tried to create scheduled action but it is not working.i want auto check out at12am everyday..

What is not working? scheduled action? please refer the blog in the given answer, it might be for v10 anyway with slight change it will work for v11 or above, if you check the existing Odoo code itself, you will get a lot of sample of the scheduled actions

Best Answer

Hi,

Here if you are looking to automatically create a checkout for those employees who forget to check out, you can create a scheduled action and calls a python function and do it.

But make sure that it will not affect/cause any issue.

You can create a scheduled action by referring to this link:  Automated action in Odoo

Then in the Python function that the action calls,

not_checkout = self.env['hr.attendance'].search([('checkout', '=', False)])
for rec in not_checkout:
date_time = 'prefered date time here'
rec.check_out = date_time


If you check the above Python code you can see that attendance which is not checked out yet is fetched and a DateTime is given as checkout time.


In the search, method make sure that the current date's record is only fetched.

Thanks

Avatar
Discard
Best Answer

Hi,

Somehow if I use this code the automatic check out is still not working. Can someone add a screenshot of their scheduled action?

Avatar
Discard
Best Answer

 hello

create an schedule action and into that set the "Execute Every 1 Days", "Next Execution Date = datetime(datetime must be like 2018-01-01 00:00:00),   code = model.cron_set_attedance_checkout(), model= Attendance"

Python code: 

class hr_attendace(models.Model)

    _inherit = 'hr.attendance'

    @api.model

    def cron_set_attedance_checkout(self):
         records = self.search([('check_out', '=', False), ('check_in', '!=', False)]):

         for record in records:

            record.check_out = record.check_in
    

Avatar
Discard

Hi Mitul
Can you send a screenshot please? Also can you do the reverse to check in as well. I prefer to have each day of the month in the attendance record so if you download the time data for the month, each day appears, days worked and off days. Just a query.