bio-metric cap issue
This commit is contained in:
parent
704ed75a10
commit
0e99df97ad
|
|
@ -79,8 +79,6 @@ class BiometricDeviceDetails(models.Model):
|
||||||
device_password = fields.Integer(string='Password',
|
device_password = fields.Integer(string='Password',
|
||||||
help='Enter the device password')
|
help='Enter the device password')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def device_connect(self, zk):
|
def device_connect(self, zk):
|
||||||
"""Function for connecting the device with Odoo"""
|
"""Function for connecting the device with Odoo"""
|
||||||
try:
|
try:
|
||||||
|
|
@ -172,39 +170,40 @@ class BiometricDeviceDetails(models.Model):
|
||||||
if conn:
|
if conn:
|
||||||
conn.disable_device()
|
conn.disable_device()
|
||||||
self.get_all_users()
|
self.get_all_users()
|
||||||
|
# self.action_set_timezone()
|
||||||
user = conn.get_users()
|
user = conn.get_users()
|
||||||
# fingers = conn.get_templates()
|
# get All Fingerprints
|
||||||
# for use in user:
|
fingers = conn.get_templates()
|
||||||
# for finger in fingers:
|
for use in user:
|
||||||
# if finger.uid == use.uid:
|
for finger in fingers:
|
||||||
# templates = conn.get_user_template(uid=use.uid,
|
if finger.uid == use.uid:
|
||||||
# temp_id=finger.fid,
|
templates = conn.get_user_template(uid=use.uid,
|
||||||
# user_id=use.user_id)
|
temp_id=finger.fid,
|
||||||
# hex_data = templates.template.hex()
|
user_id=use.user_id)
|
||||||
# # Convert hex data to binary
|
hex_data = templates.template.hex()
|
||||||
# binary_data = binascii.unhexlify(hex_data)
|
# Convert hex data to binary
|
||||||
# base64_data = base64.b64encode(binary_data).decode(
|
binary_data = binascii.unhexlify(hex_data)
|
||||||
# 'utf-8')
|
base64_data = base64.b64encode(binary_data).decode(
|
||||||
# employee = self.env['hr.employee'].search(
|
'utf-8')
|
||||||
# [('device_id_num', '=', use.user_id),('company_id', '=', self.env.company.id)],limit=1)
|
employee = self.env['hr.employee'].search(
|
||||||
# employee.device_ids |= self
|
[('device_id_num', '=', use.user_id), ('company_id', '=', self.env.company.id)],
|
||||||
# if str(finger.fid) in employee.fingerprint_ids.mapped(
|
limit=1)
|
||||||
# 'finger_id'):
|
employee.device_ids |= self
|
||||||
# employee.fingerprint_ids.search(
|
if str(finger.fid) in employee.fingerprint_ids.mapped(
|
||||||
# [('finger_id', '=', finger.fid)]).update({
|
'finger_id'):
|
||||||
# 'finger_template': base64_data,
|
employee.fingerprint_ids.search(
|
||||||
# })
|
[('finger_id', '=', finger.fid)]).update({
|
||||||
# else:
|
'finger_template': base64_data,
|
||||||
# employee.fingerprint_ids.create({
|
})
|
||||||
# 'finger_template': base64_data,
|
else:
|
||||||
# 'finger_id': finger.fid,
|
employee.fingerprint_ids.create({
|
||||||
# 'employee_bio_id': employee.id,
|
'finger_template': base64_data,
|
||||||
# 'filename': f'{employee.name}-finger-{finger.fid}'
|
'finger_id': finger.fid,
|
||||||
# })
|
'employee_bio_id': employee.id,
|
||||||
|
'filename': f'{employee.name}-finger-{finger.fid}'
|
||||||
|
})
|
||||||
# get all attendances
|
# get all attendances
|
||||||
print(help(zk.get_attendance))
|
|
||||||
attendance = conn.get_attendance()
|
attendance = conn.get_attendance()
|
||||||
print(attendance)
|
|
||||||
if attendance:
|
if attendance:
|
||||||
filtered_attendance = []
|
filtered_attendance = []
|
||||||
|
|
||||||
|
|
@ -240,50 +239,54 @@ class BiometricDeviceDetails(models.Model):
|
||||||
|
|
||||||
for uid in user:
|
for uid in user:
|
||||||
if uid.user_id == each.user_id:
|
if uid.user_id == each.user_id:
|
||||||
employee = self.env['hr.employee'].search([
|
get_user_id = self.env['hr.employee'].search(
|
||||||
('device_id_num', '=', each.user_id),
|
[('device_id_num', '=', each.user_id), ('company_id', '=', self.env.company.id)],
|
||||||
('company_id', '=', self.env.company.id)
|
limit=1)
|
||||||
], limit=1)
|
check_in_today = hr_attendance.search([(
|
||||||
|
'employee_id', '=', get_user_id.id),
|
||||||
|
('check_in', '!=', False), ('check_out', '=', False)])
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
if not employee:
|
# Define the tolerance (10 minutes)
|
||||||
continue
|
tolerance = timedelta(minutes=10)
|
||||||
|
|
||||||
# Convert atten_time to datetime
|
# Convert the atten_time string to a datetime object
|
||||||
|
|
||||||
|
# Calculate the lower and upper bounds with the tolerance
|
||||||
atten_time_obj = datetime.datetime.strptime(atten_time, "%Y-%m-%d %H:%M:%S")
|
atten_time_obj = datetime.datetime.strptime(atten_time, "%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
# Find existing attendance for today
|
# Calculate the lower and upper bounds with the tolerance
|
||||||
start_of_day = atten_time_obj.replace(hour=0, minute=0, second=0, microsecond=0)
|
lower_bound = atten_time_obj - tolerance
|
||||||
end_of_day = atten_time_obj.replace(hour=23, minute=59, second=59, microsecond=999999)
|
upper_bound = atten_time_obj + tolerance
|
||||||
|
|
||||||
attendance_today = self.env['hr.attendance'].search([
|
# Ensure the 'check_in' and 'check_out' fields are datetime objects and compare them
|
||||||
('employee_id', '=', employee.id),
|
next_in = hr_attendance.search([
|
||||||
('check_in', '>=', start_of_day),
|
('employee_id', '=', get_user_id.id),
|
||||||
('check_in', '<=', end_of_day)
|
('check_in', '>=', lower_bound),
|
||||||
], limit=1)
|
('check_in', '<=', upper_bound)
|
||||||
|
])
|
||||||
|
|
||||||
# IN logic
|
next_out = hr_attendance.search([
|
||||||
if self.display_name == 'IN':
|
('employee_id', '=', get_user_id.id),
|
||||||
if not attendance_today:
|
('check_out', '>=', lower_bound),
|
||||||
# No attendance yet, create new with check_in only
|
('check_out', '<=', upper_bound)
|
||||||
self.env['hr.attendance'].create({
|
])
|
||||||
'employee_id': employee.id,
|
if get_user_id:
|
||||||
'check_in': atten_time_obj,
|
if self.display_name == 'IN' and not check_in_today:
|
||||||
})
|
if next_in:
|
||||||
employee.attendance_state = 'checked_in'
|
|
||||||
else:
|
|
||||||
attendance_today.check_out = False
|
|
||||||
employee.attendance_state = 'checked_in'
|
|
||||||
continue
|
continue
|
||||||
|
hr_attendance.create({
|
||||||
# OUT logic
|
'employee_id': get_user_id.id,
|
||||||
elif self.display_name != 'IN':
|
'check_in': atten_time,
|
||||||
if attendance_today:
|
|
||||||
# Only update checkout if it's not set or is earlier than current atten_time
|
|
||||||
if not attendance_today.check_out or attendance_today.check_out < atten_time_obj:
|
|
||||||
attendance_today.write({
|
|
||||||
'check_out': atten_time_obj,
|
|
||||||
})
|
})
|
||||||
employee.attendance_state = 'checked_out'
|
get_user_id.attendance_state = 'checked_in'
|
||||||
|
elif check_in_today and self.display_name != 'IN':
|
||||||
|
if fields.Datetime.to_string(check_in_today.check_in) > atten_time or next_out:
|
||||||
|
continue
|
||||||
|
check_in_today.write({
|
||||||
|
'check_out': atten_time,
|
||||||
|
})
|
||||||
|
get_user_id.attendance_state = 'checked_out'
|
||||||
|
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
@ -293,7 +296,7 @@ class BiometricDeviceDetails(models.Model):
|
||||||
('company_id', '=', self.env.company.id)])
|
('company_id', '=', self.env.company.id)])
|
||||||
if not duplicate_atten_ids:
|
if not duplicate_atten_ids:
|
||||||
zk_attendance.create({
|
zk_attendance.create({
|
||||||
'employee_id': employee.id,
|
'employee_id': get_user_id.id,
|
||||||
'device_id_num': each.user_id,
|
'device_id_num': each.user_id,
|
||||||
'attendance_type': str(1),
|
'attendance_type': str(1),
|
||||||
'punch_type': '0' if self.display_name == 'IN' else '1',
|
'punch_type': '0' if self.display_name == 'IN' else '1',
|
||||||
|
|
@ -484,7 +487,6 @@ class BiometricDeviceDetails(models.Model):
|
||||||
else:
|
else:
|
||||||
raise UserError(_("Unable to establish a connection to the device."))
|
raise UserError(_("Unable to establish a connection to the device."))
|
||||||
|
|
||||||
|
|
||||||
def get_all_users(self):
|
def get_all_users(self):
|
||||||
"""Function to get all user's details"""
|
"""Function to get all user's details"""
|
||||||
for info in self:
|
for info in self:
|
||||||
|
|
@ -563,7 +565,7 @@ class BiometricDeviceDetails(models.Model):
|
||||||
"group_id: %s\n"
|
"group_id: %s\n"
|
||||||
"user_id: %s\n"
|
"user_id: %s\n"
|
||||||
"Here is the debugging information:\n%s\n"
|
"Here is the debugging information:\n%s\n"
|
||||||
"Try Reqing the device")
|
"Try Restarting the device")
|
||||||
% (candidate_uid, employee.name, privilege, password,
|
% (candidate_uid, employee.name, privilege, password,
|
||||||
group_id, str(candidate_uid), e))
|
group_id, str(candidate_uid), e))
|
||||||
conn.enable_device()
|
conn.enable_device()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue