From 774d0425d25d989b8cbf0bd4b883345c34163ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= Date: Tue, 8 Sep 2026 10:56:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E5=8B=A4=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../attendance_iot_import_user_wizard.py | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/attendance_iot/wizard/attendance_iot_import_user_wizard.py b/attendance_iot/wizard/attendance_iot_import_user_wizard.py index 2162d4036..1c663c113 100644 --- a/attendance_iot/wizard/attendance_iot_import_user_wizard.py +++ b/attendance_iot/wizard/attendance_iot_import_user_wizard.py @@ -17,17 +17,23 @@ class AttendanceIotImportUserWizard(models.TransientModel): employee_ids = self.env.context.get('default_employee_ids') if employee_ids: # 源公司:第一个选中员工的公司 - company = self.env['hr.employee'].browse(employee_ids[0]).company_id - # 「同步到全部设备」时默认带出该公司全部考勤机(排除源设备,避免和上方重复) + source_employee = self.env['hr.employee'].browse(employee_ids[0]) + company = source_employee.company_id + # 取第一个员工已关联的考勤机(如「本部3楼」),作为源设备 + source_iots = source_employee.attendance_iot_ids + # 「同步到全部设备」时才默认带出 if self.env.context.get('default_sync_to_all'): - # 取第一个选中员工已关联的考勤机作为源设备(用于排除) - source_employee = self.env['hr.employee'].browse(employee_ids[0]) - source_iot_ids = source_employee.attendance_iot_ids.ids - domain = [('company_id', '=', company.id)] - if source_iot_ids: - domain.append(('id', 'not in', source_iot_ids)) - company_iots = self.env['attendance.iot'].search(domain) - res['attendance_iot_ids'] = [(6, 0, company_iots.ids)] + if source_iots: + # 有已关联考勤机:上方显示第一个源设备,下方带出公司其余考勤机(排除源设备) + res['current_attendance_iot_id'] = source_iots[0].id + company_iots = self.env['attendance.iot'].search( + [('company_id', '=', company.id), ('id', 'not in', source_iots.ids)]) + res['attendance_iot_ids'] = [(6, 0, company_iots.ids)] + else: + # 该员工未关联任何考勤机:下方带出公司全部考勤机 + company_iots = self.env['attendance.iot'].search( + [('company_id', '=', company.id)]) + res['attendance_iot_ids'] = [(6, 0, company_iots.ids)] elif self.env.context.get('active_ids'): # 入口二:考勤机用户列表勾选进入,取第一条记录的源考勤机 active_ids = self.env.context.get('active_ids')