diff --git a/third_party_addons/hr_biometric_attendance/models/biometric_device_details.py b/third_party_addons/hr_biometric_attendance/models/biometric_device_details.py index 6fae62803..1b37daaec 100644 --- a/third_party_addons/hr_biometric_attendance/models/biometric_device_details.py +++ b/third_party_addons/hr_biometric_attendance/models/biometric_device_details.py @@ -463,11 +463,13 @@ class BiometricDeviceDetails(models.Model): "Please Check the Connection")) def button_door_unlock(self): + # Loop through device information to get IP and port for info in self: machine_ip = info.device_ip zk_port = info.port_number + try: - # Connecting with the device with the ip and port provided + # Try connecting to the device with the provided IP, port, and password zk = ZK(machine_ip, port=zk_port, timeout=15, password=self.device_password, force_udp=False, ommit_ping=False) @@ -477,7 +479,13 @@ class BiometricDeviceDetails(models.Model): "with 'pip3 install pyzk'.")) conn = self.device_connect(zk) if conn: - conn.unlock() + try: + admin_user_id = 9 # You can implement a method for this + conn.unlock(admin_user_id) # Unlock using the admin user ID + except Exception as e: + raise UserError(_("Failed to unlock door: %s") % str(e)) + else: + raise UserError(_("Unable to establish a connection to the device.")) def get_all_users(self):