我正在尝试使用Biometric Device Integration模块从生物识别设备导入考勤,但我发现它会删除每个我不想要的导入内容后的出勤率。所以我删除了它从我的机器删除考勤的功能,但在这里我再次发现,当我导入该功能重复出席时
我想要的是它将旧记录(出勤)与新记录进行比较并仅导入新记录。
@classmethod
def import_data_classmethod(
cls, biometric_machine, biometric_data_obj, biometric_user_obj,):
attendances = biometric_machine.getattendance()
# Sorted elements using user_id and timestamp
attendances.sort(key=lambda x: (x.user_id, x.timestamp))
for attendance in attendances:
user = biometric_user_obj.search([
['biometric_id', '=', int(attendance.user_id), ], ], )
if not attendance.action_perform:
continue
if not user.employee_id:
biometric_data_obj.create(
{'biometric_user_id': user.id,
'datetime': attendance.timestamp,
'action_perform': attendance.action_perform, }, )
continue
biometric_data_obj.create_hr_attendace(
user.employee_id.id, attendance.timestamp,
attendance.action_perform,
user.biometric_device.id,)
#biometric_machine.clean_attendance()
答案 0 :(得分:0)
@classmethod
def import_data_classmethod(
cls, biometric_machine, biometric_data_obj, biometric_user_obj,):
attendances = biometric_machine.getattendance()
# Sorted elements using user_id and timestamp
attendances.sort(key=lambda x: (x.user_id, x.timestamp))
for attendance in attendances:
user = biometric_user_obj.search([
['biometric_id', '=', int(attendance.user_id), ], ], )
del_atten_ids = biometric_data_obj.search([('biometric_user_id','=',user.id),('datetime','=',str(attendance.timestamp))])
if del_atten_ids:
# hr_attendance.unlink(cr,uid,del_atten_ids)
print "nothing to do"
elif not del_atten_ids:
if not attendance.action_perform:
continue
if not user.employee_id:
biometric_data_obj.create(
{'biometric_user_id': user.id,
'datetime': attendance.timestamp,
'action_perform': attendance.action_perform, }, )
continue
biometric_data_obj.create_hr_attendace(
user.employee_id.id, attendance.timestamp,
attendance.action_perform,
user.biometric_device.id,)
#biometric_machine.clean_attendance()