46 lines
1.9 KiB
Python
46 lines
1.9 KiB
Python
from odoo import fields, models, api
|
|
|
|
|
|
class AttendanceIotImportUserWizard(models.TransientModel):
|
|
_name = 'attendance.iot.import.user.wizard'
|
|
_description = 'Description'
|
|
|
|
attendance_iot_ids = fields.Many2many('attendance.iot',string='同步的考勤机', required=True)
|
|
current_attendance_iot_id = fields.Many2one('attendance.iot',string='当前被拷贝考勤机')
|
|
is_force_update = fields.Boolean(string='是否强制更新(有记录也会同步)', default=False)
|
|
|
|
def default_get(self, fields_list):
|
|
|
|
res = super(AttendanceIotImportUserWizard, self).default_get(fields_list)
|
|
active_ids = self.env.context.get('active_ids')
|
|
records = self.env['attendance.iot.user'].browse(active_ids)
|
|
|
|
res.update({
|
|
'current_attendance_iot_id':records[0].attendance_iot_id.id
|
|
})
|
|
|
|
return res
|
|
|
|
def action_import(self):
|
|
# 获取用户, employee_id
|
|
# 根据 attendance_iot_user.employ_id 批量给每个考勤机创建信息
|
|
# 完成
|
|
ids = self.env.context.get('active_ids')
|
|
records = self.env['attendance.iot.user'].browse(ids)
|
|
values = []
|
|
for attendance_iot_id in self.attendance_iot_ids:
|
|
for record in records:
|
|
# 去重,已经有的记录不再更新,
|
|
iot_user = self.env['attendance.iot.user'].search(
|
|
[('attendance_iot_id','=', attendance_iot_id.id), ('employee_id', '=', record.employee_id.id)])
|
|
if iot_user:
|
|
if not self.is_force_update:
|
|
continue
|
|
iot_user.with_context(iot_sync=True).unlink()
|
|
values.append({
|
|
'attendance_iot_id': attendance_iot_id.id,
|
|
'employee_id': record.employee_id.id
|
|
})
|
|
|
|
self.env['attendance.iot.user'].sudo().create(values)
|