diff --git a/sf_machine_connect/controllers/controllers.py b/sf_machine_connect/controllers/controllers.py index 5ba1261f..23452b43 100644 --- a/sf_machine_connect/controllers/controllers.py +++ b/sf_machine_connect/controllers/controllers.py @@ -626,10 +626,16 @@ class Sf_Dashboard_Connect(http.Controller): ('production_id.state', 'not in', ['cancel', 'done']), ('active', '=', True) ]) # print(not_done_orders) + # 完成订单 + # 获取当前时间,并计算24小时前的时间 + current_time = datetime.now() + time_24_hours_ago = current_time - timedelta(hours=24) + finish_orders = plan_obj.search([ ('production_line_id.name', '=', line), ('state', 'in', ['finished']), - ('production_id.state', 'not in', ['cancel']), ('active', '=', True) + ('production_id.state', 'not in', ['cancel']), ('active', '=', True), + ('actual_end_time', '>=', time_24_hours_ago) ]) # print(finish_orders) @@ -687,6 +693,8 @@ class Sf_Dashboard_Connect(http.Controller): not_done_data.append(line_dict) for finish_order in finish_orders: + if not finish_order.actual_end_time: + continue blank_name = '' try: blank_name = finish_order.production_id.move_raw_ids[0].product_id.name @@ -707,7 +715,7 @@ class Sf_Dashboard_Connect(http.Controller): 'material': material, 'dimensions': dimensions, 'order_qty': finish_order.product_qty, - 'finish_time': finish_order.actual_end_time.strftime('%Y-%m-%d %H:%M:%S'), + 'finish_time': finish_order.actual_end_time.strftime('%Y-%m-%d %H:%M:%S') if finish_order.actual_end_time else ' ' } done_data.append(line_dict) diff --git a/sf_maintenance/models/sf_maintenance_oee.py b/sf_maintenance/models/sf_maintenance_oee.py index 9a6aaba8..1a2e4f10 100644 --- a/sf_maintenance/models/sf_maintenance_oee.py +++ b/sf_maintenance/models/sf_maintenance_oee.py @@ -1,5 +1,9 @@ # -*- coding: utf-8 -*- +import json +import datetime +import requests from odoo import api, fields, models, _ +from odoo.exceptions import UserError class SfMaintenanceEquipmentOEE(models.Model): @@ -9,6 +13,9 @@ class SfMaintenanceEquipmentOEE(models.Model): name = fields.Char('设备oee') equipment_id = fields.Many2one('maintenance.equipment', '机台号', domain="[('category_id.equipment_type', '=', '机床'),('state_zc', '=', '已注册')]") + + equipment_code = fields.Char('设备编码', related='equipment_id.code', store=True) + type_id = fields.Many2one('sf.machine_tool.type', '型号', related='equipment_id.type_id') machine_tool_picture = fields.Binary('设备图片', related='equipment_id.machine_tool_picture') state = fields.Selection( @@ -28,6 +35,151 @@ class SfMaintenanceEquipmentOEE(models.Model): related='equipment_id.sf_maintenance_logs_ids') oee_logs = fields.One2many('maintenance.equipment.oee.logs', 'equipment_oee_id', string='运行日志') + day_logs_detail = fields.Html('日运行日志详情') + history_logs_detail = fields.Html('历史运行日志详情') + begin_time = fields.Date('开始时间') + end_time = fields.Date('结束时间') + + # 获取日志详情 + def get_day_logs(self): + config = self.env['ir.config_parameter'].sudo() + url = 'http://172.16.10.112:8069/api/logs/list' + machine_list = [self.equipment_code] + begin_time = datetime.datetime.now().strftime('%Y-%m-%d') + ' 00:00:00' + end_time = datetime.datetime.now().strftime('%Y-%m-%d') + ' 23:59:59' + + # 请求的数据 + data = { + "machine_list": str(machine_list), + "begin_time": begin_time, + "end_time": end_time + } + + print(data) + + # 发送POST请求 + response = requests.post(url, json={}, data=data) + print(response.json()) # 输出服务器返回的响应 + if response.status_code == 200: + result = response.json() + print('============', result) + if result['status'] == 1: + logs_list = result['data'][self.equipment_code] + logs_detail = '' + for log in logs_list: + print('loooooooooooooooooooogs', log) + production_name = log['production_name'] if log['production_name'] else ' ' + logs_detail += '' + log['time'] + '' + log[ + 'state'] + '' + production_name + '' + # self.day_logs_detail = '' + logs_detail + '
时间事件/状态加工工单
' + self.day_logs_detail = ''' + + + + + + + {logs_detail} +
时间事件/状态加工工单
+ '''.format(logs_detail=logs_detail) + + else: + self.day_logs_detail = '获取日志失败' + else: + self.day_logs_detail = '获取日志失败' + + # 获取历史日志详情 + def get_history_logs(self): + config = self.env['ir.config_parameter'].sudo() + url = 'http://172.16.10.112:8069/api/logs/list' + machine_list = [self.equipment_code] + if not self.begin_time: + raise UserError('请选择开始时间') + if not self.end_time: + raise UserError('请选择结束时间') + + begin_time = self.begin_time.strftime('%Y-%m-%d') + ' 00:00:00' + end_time = self.end_time.strftime('%Y-%m-%d') + ' 23:59:59' + + # 请求的数据 + data = { + "machine_list": str(machine_list), + "begin_time": begin_time, + "end_time": end_time + } + + print(data) + + # 发送POST请求 + response = requests.post(url, json={}, data=data) + print(response.json()) # 输出服务器返回的响应 + if response.status_code == 200: + result = response.json() + print('============', result) + if result['status'] == 1: + logs_list = result['data'][self.equipment_code] + logs_detail = '' + for log in logs_list: + production_name = log['production_name'] if log['production_name'] else ' ' + logs_detail += '' + log['time'] + '' + log[ + 'state'] + '' + production_name + '' + # self.day_logs_detail = '' + logs_detail + '
时间事件/状态加工工单
' + self.history_logs_detail = ''' + + + + + + + {logs_detail} +
时间事件/状态加工工单
+ '''.format(logs_detail=logs_detail) + + else: + self.history_logs_detail = '获取日志失败' + else: + self.history_logs_detail = '获取日志失败' + + # 下载历史日志 + def download_history_logs(self): + config = self.env['ir.config_parameter'].sudo() + url = 'http://172.16.10.112:8069/api/logs/list' + machine_list = [self.equipment_code] + if not self.begin_time: + raise UserError('请选择开始时间') + if not self.end_time: + raise UserError('请选择结束时间') + + begin_time = self.begin_time.strftime('%Y-%m-%d') + ' 00:00:00' + end_time = self.end_time.strftime('%Y-%m-%d') + ' 23:59:59' + + # 请求的数据 + data = { + "machine_list": str(machine_list), + "begin_time": begin_time, + "end_time": end_time + } + + print(data) + + # 发送POST请求 + response = requests.post(url, json={}, data=data) + print(response.json()) # 输出服务器返回的响应 + if response.status_code == 200: + result = response.json() + print('============', result) + if result['status'] == 1: + logs_list = result['data'][self.equipment_code] + logs_detail = '' + for log in logs_list: + production_name = log['production_name'] if log['production_name'] else ' ' + # todo 下载日志 + + else: + self.history_logs_detail = '下载日志失败' + else: + self.history_logs_detail = '下载日志失败' + def name_get(self): result = [] for parameter in self: @@ -95,4 +247,3 @@ class SfMaintenanceEquipmentOEELogDetail(models.Model): log_id = fields.Many2one('maintenance.equipment.oee.logs', '日志') # equipment_code = fields.Char('设备编码', related='log_id.equipment_code') equipment_code = fields.Char('设备编码', readonly='True') - diff --git a/sf_maintenance/views/maintenance_equipment_oee_views.xml b/sf_maintenance/views/maintenance_equipment_oee_views.xml index 9370fbbc..33749809 100644 --- a/sf_maintenance/views/maintenance_equipment_oee_views.xml +++ b/sf_maintenance/views/maintenance_equipment_oee_views.xml @@ -38,6 +38,7 @@ + @@ -48,21 +49,37 @@ - - - - - - - - - - - - - - + + + +