diff --git a/attendance_iot/models/attendance_iot.py b/attendance_iot/models/attendance_iot.py index bc9115352..3fe9a37fe 100644 --- a/attendance_iot/models/attendance_iot.py +++ b/attendance_iot/models/attendance_iot.py @@ -23,9 +23,5 @@ class AttendanceIot(models.Model): 'type': 'ir.actions.act_window', 'res_model': 'attendance.iot.user', 'view_mode': 'tree', - 'domain': [ - ('employee_id', 'in', self.employee_ids.ids), - ('attendance_iot_id', '=', self.id), - ], - 'context': {'group_by': ['company_id', 'attendance_iot_id']} + 'domain': [('attendance_iot_id', '=', self.id)], } diff --git a/attendance_iot/models/attendance_iot_manager.py b/attendance_iot/models/attendance_iot_manager.py index 2d43dac3c..74a16866c 100644 --- a/attendance_iot/models/attendance_iot_manager.py +++ b/attendance_iot/models/attendance_iot_manager.py @@ -25,70 +25,8 @@ class AttendanceIotManager(models.Model): "target": "new", } - @api.model_create_multi - def create(self, vals_list): - pass - # for vals in vals_list: - # if vals['data_selection'] == 'mqtt': - # self.mqtt_request(self, vals['attendance_number'], 'addUser') - return super().create(vals_list) - - def mqtt_request(self, attendance_number, data): - reuqired_params = self.get_required_params(data) - if any(reuqired_param not in data.keys() for reuqired_param in reuqired_params): - raise UserError(f'缺少必填参数,请确认: {",".join(reuqired_params)}') - mqtt_config = self.get_mqtt_config() - self.start_mqtt(mqtt_config) - self.publish_message(mqtt_config, f'iot/device/{attendance_number}', data) - - def get_required_params(self, cmd): - params_dict = { - 'addUser': ['cmd', 'user_id', 'name', 'id_valid'], - 'editUser': ['cmd', 'user_id', 'edit_mode'], - 'delUser': ['cmd'], - 'delMultiUser': ['cmd', 'user_ids'], - 'setPasswordVerify': ['cmd', 'value'], - 'setOpenDoorPassword': ['cmd', 'value'], - } - if cmd not in params_dict.keys(): - raise UserError(f'指令不存在,请确认,目前支持: {",".join(params_dict.keys())}') - else: - return params_dict[cmd] - - @api.model - def get_mqtt_config(self): - mqtt_config = self.search([], limit=1) - return mqtt_config - - @api.model - def start_mqtt(self, mqtt_config): - def on_connect(client, userdata, flags, rc): - if rc == 0: - _logger.info("Connected to MQTT Broker") - else: - _logger.info(f"Failed to connect, return code {rc}", ) - - def on_message(client, userdata, message): - _logger.info(f"Received message: {str(message.payload.decode('utf-8'))}", ) - client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, "OdooMQTT") - client.on_connect = on_connect - client.on_message = on_message - client.connect(mqtt_config.broker, mqtt_config.port, 60) - client.loop_start() - - @api.model - def publish_message(self, mqtt_config, topic, message): - client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, "OdooMQTT") - client.connect(mqtt_config.broker, mqtt_config.port, 60) - res = client.publish(topic, message) - if res.get('code') == 0: - _logger.info("操作成功") - else: - _logger.info(f"操作失败,返回错误码: {res.get('code')}") - client.disconnect() - def employee_message(self): - domain = [('attendance_iot_id', '=', self.attendance_iot_id.id)] + domain = [('attendance_iot_id', '=', self.name)] return { 'name': '员工列表', 'type': 'ir.actions.act_window',