From 78771fa5c24f91833b5efd10438fe02131e29f7b 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:13:57 +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/models/hr_employee.py | 6 ++++++ .../attendance_iot_import_user_wizard.py | 21 ++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/attendance_iot/models/hr_employee.py b/attendance_iot/models/hr_employee.py index 4ad55679c..0b1fadd0d 100644 --- a/attendance_iot/models/hr_employee.py +++ b/attendance_iot/models/hr_employee.py @@ -2,6 +2,7 @@ import base64 from odoo import models, fields, api, exceptions, _, tools +from odoo.exceptions import UserError class HrEmployee(models.Model): @@ -79,8 +80,13 @@ class HrEmployee(models.Model): def action_attendance_iot_batch_copy(self): # 「批量拷贝」按钮:打开弹窗,由用户手动勾选要同步到哪些考勤机 + # 没勾选任何员工时直接提示,避免进入向导后 default_get 空记录报错 + if not self: + raise UserError(_('请先在员工列表中勾选要同步的员工,再点击「批量拷贝」。')) return self._get_attendance_iot_copy_action(sync_to_all=False) def action_attendance_iot_sync_all(self): # 「同步到全部设备」按钮:打开弹窗并默认带出本公司全部考勤机 + if not self: + raise UserError(_('请先在员工列表中勾选要同步的员工,再点击「同步到全部设备」。')) return self._get_attendance_iot_copy_action(sync_to_all=True) diff --git a/attendance_iot/wizard/attendance_iot_import_user_wizard.py b/attendance_iot/wizard/attendance_iot_import_user_wizard.py index ac157c727..f363426f8 100644 --- a/attendance_iot/wizard/attendance_iot_import_user_wizard.py +++ b/attendance_iot/wizard/attendance_iot_import_user_wizard.py @@ -23,19 +23,20 @@ class AttendanceIotImportUserWizard(models.TransientModel): company_iots = self.env['attendance.iot'].search( [('company_id', '=', company.id)]) res['attendance_iot_ids'] = [(6, 0, company_iots.ids)] - else: + elif self.env.context.get('active_ids'): # 入口二:考勤机用户列表勾选进入,取第一条记录的源考勤机 active_ids = self.env.context.get('active_ids') records = self.env['attendance.iot.user'].browse(active_ids) - # 取第一条记录,作为被拷贝的源考勤机 - source_iot = records[0].attendance_iot_id - # 查出源考勤机所属公司的全部考勤机,作为同步目标默认带出(不排除源设备) - company_iots = self.env['attendance.iot'].search( - [('company_id', '=', source_iot.company_id.id)]) - res.update({ - 'current_attendance_iot_id': source_iot.id, - 'attendance_iot_ids': [(6, 0, company_iots.ids)], - }) + if records: + # 取第一条记录,作为被拷贝的源考勤机 + source_iot = records[0].attendance_iot_id + # 查出源考勤机所属公司的全部考勤机,作为同步目标默认带出(不排除源设备) + company_iots = self.env['attendance.iot'].search( + [('company_id', '=', source_iot.company_id.id)]) + res.update({ + 'current_attendance_iot_id': source_iot.id, + 'attendance_iot_ids': [(6, 0, company_iots.ids)], + }) return res def action_import(self):