diff --git a/attendance_iot/wizard/attendance_iot_import_user_wizard.py b/attendance_iot/wizard/attendance_iot_import_user_wizard.py index 00b6ec646..95ed7a29f 100644 --- a/attendance_iot/wizard/attendance_iot_import_user_wizard.py +++ b/attendance_iot/wizard/attendance_iot_import_user_wizard.py @@ -18,7 +18,8 @@ class AttendanceIotImportUserWizard(models.TransientModel): if employee_ids: # 入口一:员工列表按钮进入,取第一个选中员工的关联考勤机作为源设备 source_employee = self.env['hr.employee'].browse(employee_ids[0]) - source_iots = source_employee.attendance_iot_ids + # 用 .exists() 过滤掉已删除的孤儿记录(避免访问已删 attendance.iot 报「缺失记录」) + source_iots = source_employee.attendance_iot_ids.exists() if source_iots: # 取第一个关联考勤机为源设备:上方显示源设备,下方带出同公司其余考勤机(排除源设备,避免重复) source_iot = source_iots[0] @@ -36,7 +37,8 @@ class AttendanceIotImportUserWizard(models.TransientModel): elif self.env.context.get('active_ids'): # 入口二:考勤机用户列表勾选进入,取第一条记录的源考勤机 active_ids = self.env.context.get('active_ids') - records = self.env['attendance.iot.user'].browse(active_ids) + # 用 .exists() 过滤掉已删除的孤儿记录 + records = self.env['attendance.iot.user'].browse(active_ids).exists() if records: # 取第一条记录,作为被拷贝的源考勤机 source_iot = records[0].attendance_iot_id