1. 增加批量初始化设备功能

This commit is contained in:
sunjie
2025-07-24 16:37:35 +08:00
parent fa187dbd2e
commit 69efc924ba
2 changed files with 22 additions and 4 deletions
+16 -1
View File
@@ -18,6 +18,21 @@ class AttendanceIot(models.Model):
company_id = fields.Many2one('res.company', string="公司")
employee_ids = fields.Many2many('hr.employee', string="员工")
def action_init_device(self):
'''
初始化设备数据
'''
# 查找 员工
for record in self:
values = []
employees = self.env['hr.employee'].search([('company_id', '=', record.company_id.id)])
for employee in employees:
values.append({
'employee_id': employee.id,
'attendance_iot_id': record.id
})
self.env['attendance.iot.user'].create(values)
def open_record(self):
self.ensure_one()
return {
@@ -26,7 +41,7 @@ class AttendanceIot(models.Model):
'res_model': 'attendance.iot.user',
'view_mode': 'tree',
'domain': [('attendance_iot_id', '=', self.id)],
'context':{'default_attendance_iot_id':self.id}
'context': {'default_attendance_iot_id': self.id}
}
def compute_iot_num(self):
@@ -5,11 +5,14 @@
<field name="model">attendance.iot</field>
<field name="arch" type="xml">
<tree editable="bottom">
<header>
<button name="action_init_device" string="初始化设备" type="object"/>
</header>
<field name="name"/>
<field name="attendance_address"/>
<!-- <field name="broker" optional="hide"/>-->
<!-- <field name="port" optional="hide"/>-->
<!-- <field name="id_valid" optional="hide"/>-->
<!-- <field name="broker" optional="hide"/>-->
<!-- <field name="port" optional="hide"/>-->
<!-- <field name="id_valid" optional="hide"/>-->
<field name="company_id"/>
<field name="number"/>
<button name="open_record" type="object" string="详情" class="btn-primary"/>