增加设备oee数据
This commit is contained in:
@@ -764,3 +764,111 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
finally:
|
finally:
|
||||||
cur.close()
|
cur.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
# 设备oee
|
||||||
|
@http.route('/api/OEE', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*")
|
||||||
|
def OEE(self, **kw):
|
||||||
|
"""
|
||||||
|
获取产线等oee
|
||||||
|
"""
|
||||||
|
res = {'status': 1, 'message': '成功', 'data': {}}
|
||||||
|
logging.info('前端请求oee数据的参数为:%s' % kw)
|
||||||
|
|
||||||
|
try:
|
||||||
|
count_oee = 1
|
||||||
|
workcenter_obj = request.env['mrp.workcenter'].sudo()
|
||||||
|
workcenter_list = ast.literal_eval(kw['workcenter_list'])
|
||||||
|
print('workcenter_list: %s' % workcenter_list)
|
||||||
|
for line in workcenter_list:
|
||||||
|
res['data'][line] = workcenter_obj.search([('name', '=', line)]).oee
|
||||||
|
count_oee *= workcenter_obj.search([('name', '=', line)]).oee
|
||||||
|
res['data']['综合oee'] = count_oee / 1000000
|
||||||
|
except Exception as e:
|
||||||
|
print(f"An error occurred: {e}")
|
||||||
|
|
||||||
|
return json.dumps(res)
|
||||||
|
|
||||||
|
# # 查询某段时间的设备oee
|
||||||
|
# @http.route('/api/OEEByTime', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*")
|
||||||
|
# def OEEByTime(self, **kw):
|
||||||
|
# """
|
||||||
|
# 获取某段时间的oee
|
||||||
|
# """
|
||||||
|
# res = {'status': 1, 'message': '成功', 'data': {}}
|
||||||
|
# logging.info('前端请求获取某段时间的oee的参数为:%s' % kw)
|
||||||
|
# workcenter_list = ast.literal_eval(kw['workcenter_list'])
|
||||||
|
# begin_time_str = kw['begin_time'].strip('"')
|
||||||
|
# end_time_str = kw['end_time'].strip('"')
|
||||||
|
# begin_time = datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S')
|
||||||
|
# end_time = datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S')
|
||||||
|
# print('workcenter_list: %s' % workcenter_list)
|
||||||
|
# # 连接数据库
|
||||||
|
# conn = psycopg2.connect(**db_config)
|
||||||
|
# cur = conn.cursor()
|
||||||
|
# # 查询并计算OEE平均值
|
||||||
|
# oee_data = {}
|
||||||
|
# for workcenter in workcenter_list:
|
||||||
|
# cur.execute("""
|
||||||
|
# SELECT AVG(oee) as avg_oee
|
||||||
|
# FROM oee_data
|
||||||
|
# WHERE workcenter_name = %s
|
||||||
|
# AND time BETWEEN %s AND %s
|
||||||
|
# """, (workcenter, begin_time, end_time))
|
||||||
|
#
|
||||||
|
# result = cur.fetchone()
|
||||||
|
# avg_oee = result[0] if result else 0.0
|
||||||
|
# oee_data[workcenter] = avg_oee
|
||||||
|
#
|
||||||
|
# # 返回数据
|
||||||
|
# res['data'] = oee_data
|
||||||
|
# return json.dumps(res)
|
||||||
|
|
||||||
|
@http.route('/api/OEEByTime', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*")
|
||||||
|
def OEEByTime(self, **kw):
|
||||||
|
"""
|
||||||
|
获取某段时间的oee,根据用户指定的时间单位(day或hour)返回对应的平均值
|
||||||
|
"""
|
||||||
|
res = {'status': 1, 'message': '成功', 'data': {}}
|
||||||
|
logging.info('前端请求获取某段时间的oee的参数为:%s' % kw)
|
||||||
|
|
||||||
|
# 获取并解析参数
|
||||||
|
workcenter_list = ast.literal_eval(kw['workcenter_list'])
|
||||||
|
begin_time_str = kw['begin_time'].strip('"')
|
||||||
|
end_time_str = kw['end_time'].strip('"')
|
||||||
|
time_unit = kw.get('time_unit', 'day') # 默认单位为天
|
||||||
|
begin_time = datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S')
|
||||||
|
end_time = datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
|
# 连接数据库
|
||||||
|
conn = psycopg2.connect(**db_config)
|
||||||
|
cur = conn.cursor()
|
||||||
|
|
||||||
|
# 根据时间单位选择不同的时间格式
|
||||||
|
if time_unit == 'hour':
|
||||||
|
time_format = 'YYYY-MM-DD HH24:00:00'
|
||||||
|
else: # 默认为'day'
|
||||||
|
time_format = 'YYYY-MM-DD'
|
||||||
|
|
||||||
|
# 查询并计算OEE平均值
|
||||||
|
oee_data = {}
|
||||||
|
for workcenter in workcenter_list:
|
||||||
|
cur.execute(f"""
|
||||||
|
SELECT to_char(time, '{time_format}') as time_unit, AVG(oee) as avg_oee
|
||||||
|
FROM oee_data
|
||||||
|
WHERE workcenter_name = %s
|
||||||
|
AND time BETWEEN %s AND %s
|
||||||
|
GROUP BY time_unit
|
||||||
|
ORDER BY time_unit
|
||||||
|
""", (workcenter, begin_time, end_time))
|
||||||
|
|
||||||
|
results = cur.fetchall()
|
||||||
|
oee_data[workcenter] = {row[0]: row[1] for row in results}
|
||||||
|
|
||||||
|
# 关闭数据库连接
|
||||||
|
cur.close()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
# 返回数据
|
||||||
|
res['data'] = oee_data
|
||||||
|
return json.dumps(res)
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class ResWorkcenter(models.Model):
|
|||||||
|
|
||||||
oee_target = fields.Float(
|
oee_target = fields.Float(
|
||||||
string='OEE Target', help="Overall Effective Efficiency Target in percentage", default=90, tracking=True)
|
string='OEE Target', help="Overall Effective Efficiency Target in percentage", default=90, tracking=True)
|
||||||
|
oee = fields.Float(compute='_compute_oee', help='Overall Equipment Effectiveness, based on the last month', store=True)
|
||||||
|
|
||||||
time_start = fields.Float('Setup Time', tracking=True)
|
time_start = fields.Float('Setup Time', tracking=True)
|
||||||
time_stop = fields.Float('Cleanup Time', tracking=True)
|
time_stop = fields.Float('Cleanup Time', tracking=True)
|
||||||
|
|||||||
@@ -1154,10 +1154,10 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
def button_finish(self):
|
def button_finish(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
if record.routing_type == '装夹预调':
|
if record.routing_type == '装夹预调':
|
||||||
if not record.material_center_point or record.X_deviation_angle <= 0:
|
|
||||||
raise UserError("请对前置三元检测定位参数进行计算定位")
|
|
||||||
if not record.rfid_code and record.is_rework is False:
|
if not record.rfid_code and record.is_rework is False:
|
||||||
raise UserError("请扫RFID码进行绑定")
|
raise UserError("请扫RFID码进行绑定")
|
||||||
|
if not record.material_center_point or record.X_deviation_angle <= 0:
|
||||||
|
raise UserError("请对前置三元检测定位参数进行计算定位")
|
||||||
record.process_state = '待加工'
|
record.process_state = '待加工'
|
||||||
# record.write({'process_state': '待加工'})
|
# record.write({'process_state': '待加工'})
|
||||||
record.production_id.process_state = '待加工'
|
record.production_id.process_state = '待加工'
|
||||||
|
|||||||
Reference in New Issue
Block a user