Closed citronpower closed 5 years ago
The problem maybe is because you have several tabs opened?
No... Unfortunately its not the problem. It really happens when doing the check-in/check-out too fast (for example when many employees are leaving). If we wait enough between two check (until the greeting message page has left ~), this problem doesnt seem to occur.
This has happened to me too. Sometimes, when an employee does check-in/out, there are multiple check-in records in the system which blocks future records.
It looked like the scanner was sending data too quickly without delay in between, but when I tested with a text editor, there was a delay - so not the problem with scanner. Even if there is a buggy scanner which sends data with no delay, it should be in-out-in-out, not in-in-in.
I could not find the problem, had to inherit the attendance_scan(self, barcode)
function to discard the second scan of the same user within five seconds.
@hw-aka can I ask for your inherited function attendance_scan(self, barcode)
? It will probably solve my problem as well, I would be thankful!
@citronpower Sure.
from odoo import api, fields, models, _
from datetime import datetime
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
class HrAttendanceFix(models.Model):
_inherit = 'hr.employee'
@api.model
def attendance_scan(self, barcode):
""" Receive a barcode scanned from the Kiosk Mode and change the attendances of corresponding employee.
Returns either an action or a warning.
"""
employee = self.search([('barcode', '=', barcode)], limit=1)
# Duplicate fix: no scan for the same person within 5 secs ###
last_attendance_obj = self.env['hr.attendance'].search([
('employee_id', '=', employee.id)
], order='id desc', limit=1)
to_check = False
if last_attendance_obj.check_out:
last_activity_time = last_attendance_obj.check_out
to_check = True
elif last_attendance_obj.check_in:
last_activity_time = last_attendance_obj.check_in
to_check = True
if to_check and (datetime.strptime(fields.Datetime.now(), DEFAULT_SERVER_DATETIME_FORMAT) - datetime.strptime(last_activity_time, DEFAULT_SERVER_DATETIME_FORMAT)).seconds < 5.0:
return {'warning': _('%(employee)s, please let go your card from the QR scanner.') % {'employee': employee.name.split()[0]}}
# End of fix
return employee and employee.attendance_action('hr_attendance.hr_attendance_action_kiosk_mode') or \
{'warning': _('No employee corresponding to barcode %(barcode)s') % {'barcode': barcode}}
Impacted versions: Odoo11
Steps to reproduce: While check-in/check-out to quickly in Kiosk mode with badges
Current behavior: Multiple records are saved instead of one and create problem at the next check-in/check-out because there is a record which has not been checked-out but also an other, more recent, which has been check-out. Then Odoo is confused.
Solution found (if someone could check it and, if it is in order, pull it): Change in hr_attendance/static/src/js/greeting_message.js function start():
Thanks in advance for your feedback.