Files
test/sf_manufacturing/controllers/controllers.py

695 lines
38 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
import logging
import json
from datetime import datetime
from odoo.addons.sf_manufacturing.models.agv_scheduling import RepeatTaskException
from odoo import http
from odoo.http import request
class Manufacturing_Connect(http.Controller):
@http.route('/AutoDeviceApi/GetWoInfo', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False,
cors="*")
def get_Work_Info(self, **kw):
"""
自动化传递工单号获取工单信息
:param kw:
:return:
"""
logging.info('get_Work_Info:%s' % kw)
try:
res = {'Succeed': True, 'Datas': []}
datas = request.httprequest.data
ret = json.loads(datas)
request.env['center_control.interface.log'].sudo().create(
{'content': ret, 'name': 'AutoDeviceApi/GetWoInfo'})
logging.info('RfidCode:%s' % ret['RfidCode'])
if 'RfidCode' in ret:
workorder = request.env['mrp.workorder'].sudo().search(
[('rfid_code', '=', ret['RfidCode']), ('state', '!=', 'rework')])
if workorder:
for item in workorder:
res['Datas'].append({
'BillId': item.production_id.name,
'ProductionLine': item.production_id.production_line_id.id,
'SortId': item.sequence,
'CraftName': item.name,
'Quantity': 1,
'MaterialId': item.product_id.default_code,
'MaterialName': item.product_id.name,
'Spec': '%s×%s×%s' % (item.move_raw_ids.materiel_length, item.move_raw_ids.materiel_width,
item.move_raw_ids.materiel_height),
'Material': item.product_id.materials_type_id.name
})
else:
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '该rfid暂未有对应的工单'}
else:
res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传RfidCode字段'}
except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('get_Work_Info error:%s' % e)
return json.JSONEncoder().encode(res)
@http.route('/AutoDeviceApi/GetShiftPlan', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False,
cors="*")
def get_ShiftPlan(self, **kw):
"""
自动化每天获取机台日计划
:param kw:
:return:
"""
logging.info('get_ShiftPlan:%s' % kw)
try:
res = {'Succeed': True, 'Datas': []}
datas = request.httprequest.data
ret = json.loads(datas)
request.env['center_control.interface.log'].sudo().create(
{'content': ret, 'name': 'AutoDeviceApi/GetShiftPlan'})
if 'ProductionLine' in ret:
workorder_ids = request.env['mrp.workorder'].sudo().get_plan_workorder(ret['ProductionLine'])
else:
ProductionLine = False
workorder_ids = request.env['mrp.workorder'].sudo().get_plan_workorder(ProductionLine)
# todo 需要筛选出CNC工单
logging.info('RfidCode:%s' % ret)
logging.info('workorder_ids:%s' % workorder_ids)
workorder = request.env['mrp.workorder'].sudo().search(workorder_ids)
if workorder:
for item in workorder:
date_planned_start = ''
date_planned_finished = ''
if item.date_planned_start is not False:
logging.info('date_planned_start:%s' % item.date_planned_start)
planned_start = item.date_planned_start.strftime("%Y-%m-%d %H:%M:%S")
date_planned_start = request.env['sf.sync.common'].sudo().get_add_time(planned_start)
if item.date_planned_finished is not False:
logging.info('date_planned_finished:%s' % item.date_planned_finished)
planned_finished = item.date_planned_finished.strftime("%Y-%m-%d %H:%M:%S")
date_planned_finished = request.env['sf.sync.common'].sudo().get_add_time(planned_finished)
res['Datas'].append({
'BillId': item.production_id.name,
'RfidCode': item.rfid_code,
'CraftName': item.name,
'Quantity': 1,
'WortkStart': date_planned_start,
'WorkEnd': date_planned_finished,
'MaterialId': item.product_id.default_code,
'MaterialName': item.product_id.name,
# 'Spec':item.mat,
'Material': item.product_id.materials_type_id.name
})
except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('get_ShiftPlan error:%s' % e)
return json.JSONEncoder().encode(res)
@http.route('/AutoDeviceApi/QcCheck', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False,
cors="*")
def get_qcCheck(self, **kw):
"""
工件预调(前置三元检测)
1、前置三元检测在产线外三元检测设备把测量信息上传给MES
MES生成检测定位数据。中控系统传递RFID编号给MES获取测量偏置结果。来源为三元检测工单上的字段
:param kw:
:return:
"""
logging.info('get_qcCheck:%s' % kw)
try:
res = {'Succeed': True, 'Datas': []}
datas = request.httprequest.data
ret = json.loads(datas)
request.env['center_control.interface.log'].sudo().create(
{'content': ret, 'name': 'AutoDeviceApi/QcCheck'})
logging.info('RfidCode:%s' % ret['RfidCode'])
if 'RfidCode' in ret:
workorder = request.env['mrp.workorder'].sudo().search(
[('routing_type', '=', '装夹预调'), ('rfid_code', '=', ret['RfidCode']), ('state', '!=', 'rework')],
limit=1, order='id asc')
if workorder:
for item in workorder:
if item.material_center_point:
offset = item.material_center_point[1:-1].split(",")
res['Datas'].append({
'XOffset': 0 if not item.material_center_point else offset[0],
'YOffset': 0 if not item.material_center_point else offset[1],
'ZOffset': 0 if not item.material_center_point else offset[2],
'COffset': 0,
'Coordinate': 'G54'
})
else:
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '该rfid暂未有对应的工件预调(前置三元检测)工单'}
else:
res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传RfidCode字段'}
except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('get_qcCheck error:%s' % e)
return json.JSONEncoder().encode(res)
@http.route('/AutoDeviceApi/FeedBackStart', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
cors="*")
def button_Work_START(self, **kw):
"""
工单任务开始
:param kw:
:return:
"""
logging.info('button_Work_START:%s' % kw)
try:
res = {'Succeed': True, 'Datas': ['工单已开始']}
datas = request.httprequest.data
ret = json.loads(datas)
request.env['center_control.interface.log'].sudo().create(
{'content': ret, 'name': 'AutoDeviceApi/FeedBackStart'})
production_id = ret['BillId']
routing_type = ret['CraftId']
equipment_id = ret["DeviceId"]
workorder = request.env['mrp.workorder'].sudo().search(
[('production_id', '=', production_id), ('routing_type', '=', routing_type),
('rfid_code', '!=', False), ('state', '!=', 'rework')], limit=1)
if not workorder:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '该工单不存在'}
return json.JSONEncoder().encode(res)
logging.info('workorder_state:%s' % workorder.state)
if workorder.state != 'ready':
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '工单未就绪'}
return json.JSONEncoder().encode(res)
work_equipment_id = request.env['maintenance.equipment'].sudo().search([('name', '=', equipment_id)],
limit=1)
logging.info('work_equipment_id:%s' % work_equipment_id.name)
if not work_equipment_id:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '没有找到该加工设备'}
return json.JSONEncoder().encode(res)
workorder.equipment_id = work_equipment_id
workorder.button_start()
# 根据工单的实际开始时间修改排程单的开始时间、状态
if workorder.date_start:
request.env['sf.production.plan'].sudo().search([('production_id', '=', production_id)]).write(
{'actual_start_time': workorder.date_start,
'state': 'processing'})
res.update({'workorder_id': workorder.id})
except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('button_Work_START error:%s' % e)
return json.JSONEncoder().encode(res)
@http.route('/AutoDeviceApi/FeedBackEnd', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
cors="*")
def button_Work_End(self, **kw):
"""
工单任务结束
:param kw:
:return:
"""
logging.info('button_Work_End:%s' % kw)
try:
res = {'Succeed': True, 'Datas': ['工单已结束']}
datas = request.httprequest.data
ret = json.loads(datas)
logging.info('button_Work_End:%s' % ret)
request.env['center_control.interface.log'].sudo().create(
{'content': ret, 'name': 'AutoDeviceApi/FeedBackEnd'})
production_id = ret['BillId']
routing_type = ret['CraftId']
workorder = request.env['mrp.workorder'].sudo().search(
[('production_id', '=', production_id), ('routing_type', '=', routing_type),
('rfid_code', '!=', False), ('state', '!=', 'rework')], limit=1)
if not workorder:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '该工单不存在'}
return json.JSONEncoder().encode(res)
if workorder.state != 'progress':
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '该工单未开始'}
return json.JSONEncoder().encode(res)
# workorder.write({'date_finished': datetime.now()})
if ret['IsComplete'] is True:
workorder.write({'date_finished': datetime.now()})
# workorder.process_state = '待解除装夹'
# workorder.sudo().production_id.process_state = '待解除装夹'
# 根据工单的实际结束时间修改排程单的结束时间、状态,同时修改销售订单的状态
# if workorder.date_finished:
# request.env['sf.production.plan'].sudo().search([('production_id', '=', production_id)]).write(
# {'actual_end_time': workorder.date_finished,
# 'state': 'finished'})
# production_obj = request.env['mrp.production'].sudo().search([('name', '=', production_id)])
# if production_obj:
# production_obj.sudo().work_order_state = '已完成'
# production_obj.write({'state': 'done'})
# request.env['sale.order'].sudo().search(
# [('name', '=', production_obj.origin)]).write({'schedule_status': 'to deliver'})
except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('button_Work_End error:%s' % e)
return json.JSONEncoder().encode(res)
@http.route('/AutoDeviceApi/PartQualityInspect', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
cors="*")
def PartQualityInspect(self, **kw):
"""
零件质检
:param kw:
:return:
"""
logging.info('PartQualityInspect:%s' % kw)
try:
res = {'Succeed': True}
datas = request.httprequest.data
ret = json.loads(datas)
request.env['center_control.interface.log'].sudo().create(
{'content': ret, 'name': 'AutoDeviceApi/PartQualityInspect'})
production_id = ret['BillId']
# routing_type = ret['CraftId']
workorder = request.env['mrp.workorder'].sudo().search(
[('production_id', '=', production_id), ('routing_type', '=', 'CNC加工'),
('state', 'not in', ['rework', 'done', 'cancel'])], order='sequence asc',
limit=1)
if workorder:
# workorder.test_results = ret['Quality']
logging.info('制造订单:%s' % workorder.production_id.name)
if 'ReportPaht' in ret:
if ret['ReportPaht'].find('.pdf') != -1:
download_state = request.env['mrp.workorder'].with_user(
request.env.ref("base.user_admin")).download_reportfile_tmp(workorder,
ret['ReportPaht'])
if download_state is True:
detection_ret = request.env['mrp.workorder'].with_user(
request.env.ref("base.user_admin")).get_detection_file(workorder, ret['ReportPaht'])
logging.info('detection_ret:%s' % detection_ret)
if detection_ret is False:
res = {'Succeed': False, 'ErrorCode': 205, 'Error': '检测报告文件读取失败'}
else:
res = {'Succeed': False, 'ErrorCode': 204, 'Error': '检测报告文件从FTP拉取失败'}
else:
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '未传ReportPaht字段'}
else:
res = {'Succeed': False, 'ErrorCode': 206, 'Error': '未查询到工单'}
except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('PartQualityInspect error:%s' % e)
return json.JSONEncoder().encode(res)
@http.route('/AutoDeviceApi/CMMProgDolod', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
cors="*")
def CMMProgDolod(self, **kw):
"""
中控系统传递RFID编号给MES获取测量程序文件。Ftp下载文件
:param kw:
:return:
"""
logging.info('CMMProgDolod:%s' % kw)
try:
res = {'Succeed': True, 'Datas': []}
datas = request.httprequest.data
ret = json.loads(datas)
request.env['center_control.interface.log'].sudo().create(
{'content': ret, 'name': 'AutoDeviceApi/CMMProgDolod'})
if 'RfidCode' in ret:
logging.info('RfidCode:%s' % ret['RfidCode'])
workorder = request.env['mrp.workorder'].sudo().search(
[('rfid_code', '=', ret['RfidCode']), ('routing_type', '=', 'CNC加工'), ('state', '!=', 'rework')])
if workorder:
for item in workorder.cmm_ids:
if item.program_create_date is not False:
program_create_date = item.program_create_date.strftime("%Y-%m-%d %H:%M:%S")
program_date_str = request.env['sf.sync.common'].sudo().get_add_time(program_create_date)
res['Datas'].append({
'CraftId': workorder.id,
'CraftKey': workorder.name,
'ProgramDate': '' if not item.program_create_date else program_date_str,
'ProgramPath': item.program_path,
'PostProcessing': item.program_name,
})
else:
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '暂无工单及对应的CNC程序数据'}
else:
res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传RfidCode字段'}
except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('CMMProgDolod error:%s' % e)
return json.JSONEncoder().encode(res)
@http.route('/AutoDeviceApi/NCProgDolod', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
cors="*")
def NCProgDolod(self, **kw):
"""
中控系统传递RFID编号给MES获取程序单及程序文件。Ftp下载文件
:param kw:
:return:
"""
logging.info('NCProgDolod:%s' % kw)
try:
res = {'Succeed': True, 'Datas': []}
datas = request.httprequest.data
ret = json.loads(datas)
request.env['center_control.interface.log'].sudo().create(
{'content': ret, 'name': 'AutoDeviceApi/NCProgDolod'})
if 'RfidCode' in ret:
logging.info('RfidCode:%s' % ret['RfidCode'])
workorder = request.env['mrp.workorder'].sudo().search(
[('rfid_code', '=', ret['RfidCode']), ('routing_type', '=', 'CNC加工'), ('state', '!=', 'rework')])
if workorder:
for item in workorder.cnc_ids:
res['Datas'].append({
'CraftId': workorder.id,
'CraftName': workorder.name,
'SortId': item.sequence_number,
'ProgramName': item.program_name,
'ToolId': item.cutting_tool_no,
'ToolName': item.cutting_tool_name,
'Depth': item.depth_of_processing_z,
'ProgramPath': item.program_path,
'ProgramTime': item.estimated_processing_time,
})
else:
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '暂无工单及对应的CNC程序数据'}
else:
res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传RfidCode字段'}
except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('NCProgDolod error:%s' % e)
return json.JSONEncoder().encode(res)
@http.route('/AutoDeviceApi/LocationChange', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False,
cors="*")
def LocationChange(self, **kw):
"""
库位变更
:param kw:
:return:
"""
logging.info('LocationChange:%s' % kw)
try:
res = {'Succeed': True, 'Datas': []}
datas = request.httprequest.data
ret = json.loads(datas)
request.env['center_control.interface.log'].sudo().create(
{'content': ret, 'name': 'AutoDeviceApi/LocationChange'})
logging.info('库位变更LocationChange_ret:%s' % ret)
RfidCode = ret['RfidCode']
ChangeType = ret['ChangeType']
OldDeciveId = ret['OldDeciveId']
OldPosition = ret['OldPosition']
NewDeciveId = ret['NewDeciveId']
NewPosition = ret['NewPosition']
OldDeciveStart = ret['OldDeciveStart']
OldDeciveEnd = ret['OldDeciveEnd']
if ChangeType == 'Part':
temp_val_sn_id = None
old_localtion = None
# if ChangeType == 'Part' or ChangeType == 'Tool':
stock_lot_obj = request.env['stock.lot'].sudo().search(
[('rfid', '=', RfidCode)], limit=1)
logging.info('stock_lot_obj===========:%s' % stock_lot_obj)
if not stock_lot_obj:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '未根据RfidCode找到该产品'}
return json.JSONEncoder().encode(res)
if OldPosition:
old_localtion = request.env['sf.shelf.location'].sudo().search(
[('barcode', '=', OldPosition)], limit=1)
logging.info('old_localtion===========:%s' % old_localtion)
new_localtion = request.env['sf.shelf.location'].sudo().search(
[('barcode', '=', NewPosition)], limit=1)
logging.info('new_localtion===========:%s' % new_localtion)
if not new_localtion:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '没有该目标位置'}
return json.JSONEncoder().encode(res)
if old_localtion:
temp_val_sn_id = old_localtion.product_sn_id
logging.info('temp_val_sn_id===========:%s' % temp_val_sn_id)
old_localtion.product_sn_id = None
new_localtion.product_sn_id = temp_val_sn_id
logging.info('====1======')
else:
new_localtion.product_sn_id = stock_lot_obj.id
logging.info('=====2======')
elif ChangeType == 'Tool':
# 对功能刀具库位变更信息进行更改
def write_tool(DeciveId):
if 'Tool' in DeciveId:
shelfinfo = list(filter(lambda x: x.get('DeviceId') == DeciveId,
request.env['sf.shelf.location'].sudo().get_sf_shelf_location_info(
DeciveId)))
total_data = request.env['sf.shelf.location.datasync'].sudo().get_total_data()
for item in shelfinfo:
logging.info('货架已获取信息:%s' % item)
shelf_barcode = request.env['sf.shelf.location.datasync'].sudo().find_our_code(
total_data, item['Postion'])
location_id = request.env['sf.shelf.location'].sudo().search(
[('barcode', '=', shelf_barcode)],
limit=1)
if location_id:
# 如果是线边刀库信息,则对功能刀具移动生成记录
if 'Tool' in item['Postion']:
tool = request.env['sf.functional.cutting.tool.entity'].sudo().search(
[('rfid', '=', item['RfidCode']), ('functional_tool_status', '!=', '已拆除')])
tool.sudo().tool_in_out_stock_location(location_id)
if tool:
location_id.product_sn_id = tool.barcode_id.id
# 修改功能刀具状态
if item.get('State') == '报警':
if tool.functional_tool_status != item.get('State'):
tool.write({
'functional_tool_status': item['State']
})
else:
location_id.product_sn_id = False
if item['RfidCode']:
logging.info('Rfid为【%s】的功能刀具在系统中不存在!' % item['RfidCode'])
else:
equipment_id = request.env['maintenance.equipment'].sudo().search([('name', '=', DeciveId)])
if equipment_id:
equipment_id.sudo().register_equipment_tool()
else:
res_1 = {'Succeed': False, 'ErrorCode': 202, 'Error': f'设备【{DeciveId}】不存在'}
return json.JSONEncoder().encode(res_1)
if OldDeciveId:
write_tool(OldDeciveId)
elif NewDeciveId:
write_tool(NewDeciveId)
except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('LocationChange error:%s' % e)
return json.JSONEncoder().encode(res)
@http.route('/AutoDeviceApi/AGVToProduct', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
cors="*")
def AGVToProduct(self, **kw):
"""
AGV运送上产线完成
:param kw:
:return:
"""
logging.info('AGVToProduct:%s' % kw)
try:
res = {'Succeed': True}
datas = request.httprequest.data
ret = json.loads(datas)
request.env['center_control.interface.log'].sudo().create(
{'content': ret, 'name': 'AutoDeviceApi/AGVToProduct'})
logging.info('ret:%s' % ret)
if 'DeviceId' in ret:
logging.info('DeviceId:%s' % ret['DeviceId'])
if 'IsComplete' in ret:
rfid_codes = []
workorder_ids = []
if ret['IsComplete'] is True or ret['IsComplete'] is False:
for i in range(1, 5):
logging.info('F-RfidCode:%s' % i)
if f'RfidCode{i}' in ret:
rfid_code = ret[f'RfidCode{i}']
logging.info('RfidCode:%s' % rfid_code)
if rfid_code is not None and rfid_code != '':
rfid_codes.append(rfid_code)
domain = [
('rfid_code', '=', rfid_code),
('routing_type', '=', 'CNC加工'), ('state', '!=', 'rework')
]
workorder = request.env['mrp.workorder'].sudo().search(domain, order='id asc')
if workorder:
for order in workorder:
workorder_ids.append(order.id)
if order.production_line_state == '待上产线':
logging.info(
'工单产线状态:%s' % order.production_line_state)
panel_workorder = request.env['mrp.workorder'].sudo().search(
[('rfid_code', '=', rfid_code), ('state', '!=', 'rework'),
('processing_panel', '=', order.processing_panel)])
if panel_workorder:
panel_workorder.write({'production_line_state': '已上产线'})
# workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search(
# [
# ('rfid_code', '=', rfid_code), ('type', '=', '上产线'),
# ('production_id', '=', order.production_id.id),
# ('workorder_id', '=', order.id),
# ('workorder_state', '=', 'done')])
# if workpiece_delivery.status == '待下发':
# workpiece_delivery.write({'is_manual_work': True})
# 下发
else:
res = {'Succeed': False, 'ErrorCode': 204,
'Error': 'DeviceId为%s没有对应的已配送工件数据' % ret['DeviceId']}
if ret['IsComplete'] is True:
# 向AGV任务调度下发运送空料架任务
workorders = request.env['mrp.workorder'].browse(workorder_ids)
request.env['sf.agv.scheduling'].add_scheduling(ret['DeviceId'], '运送空料架', workorders)
else:
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '未传IsComplete字段'}
else:
res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传DeviceId字段'}
except RepeatTaskException as e:
logging.info('AGVToProduct error:%s' % e)
except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': str(e)}
logging.info('AGVToProduct error:%s' % e)
return json.JSONEncoder().encode(res)
@http.route('/AutoDeviceApi/AGVDownProduct', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
cors="*")
def AGVDownProduct(self, **kw):
"""
MES调度AGV搬运零件AGV托盘到产线接驳站。
生产线接受到零件AGV托盘到位信号后把生产合格或特采的零件机器人搬运零件到AGV接驳站中触发AGV运送下产线接口。
:param kw:
:return:
"""
logging.info('AGVDownProduct:%s' % kw)
try:
res = {'Succeed': True}
datas = request.httprequest.data
ret = json.loads(datas)
request.env['center_control.interface.log'].sudo().create(
{'content': ret, 'name': 'AutoDeviceApi/AGVDownProduct'})
logging.info('ret:%s' % ret)
if 'DeviceId' in ret:
logging.info('DeviceId:%s' % ret['DeviceId'])
# delivery_Arr = []
workorder_ids = []
if 'IsComplete' in ret:
if ret['IsComplete'] is True or ret['IsComplete'] is False:
for i in range(1, 5):
logging.info('F-RfidCode:%s' % i)
if f'RfidCode{i}' in ret:
rfid_code = ret[f'RfidCode{i}']
logging.info('RfidCode:%s' % rfid_code)
if rfid_code is not None and rfid_code != '':
domain = [
('rfid_code', '=', rfid_code),
('routing_type', '=', 'CNC加工'), ('state', '!=', 'rework')
]
workorder = request.env['mrp.workorder'].sudo().search(domain, order='id asc')
if workorder:
for order in workorder:
workorder_ids.append(order.id)
if order.production_line_state == '已上产线':
logging.info(
'工单产线状态:%s' % order.production_line_state)
panel_workorder = request.env['mrp.workorder'].sudo().search(
[('rfid_code', '=', rfid_code), ('state', '!=', 'rework'),
('processing_panel', '=', order.processing_panel)])
if panel_workorder:
panel_workorder.write({'production_line_state': '已下产线'})
workorder.write({'state': 'to be detected'})
workorder.check_ids.filtered(
lambda ch: ch.quality_state == 'waiting').write(
{'quality_state': 'none'})
else:
res = {'Succeed': False, 'ErrorCode': 204,
'Error': 'DeviceId为%s没有对应的已配送工件数据' % ret['DeviceId']}
# if delivery_Arr:
# logging.info('delivery_Arr:%s' % delivery_Arr)
# delivery_workpiece = request.env['sf.workpiece.delivery'].sudo().search(
# [('id', 'in', delivery_Arr)])
# if delivery_workpiece:
# logging.info('开始向agv下发下产线任务')
# agv_site = request.env['sf.agv.site'].sudo().search([])
# if agv_site:
# has_site = agv_site.update_site_state()
# if has_site is True:
# is_free = delivery_workpiece._check_avgsite_state()
# if is_free is True:
# delivery_workpiece._delivery_avg()
# logging.info('agv下发下产线任务下发完成')
if ret['IsComplete'] is True:
# 向AGV任务调度下发下产线任务
workorders = request.env['mrp.workorder'].browse(workorder_ids)
request.env['sf.agv.scheduling'].add_scheduling(ret['DeviceId'], '下产线', workorders)
else:
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '未传IsComplete字段'}
except RepeatTaskException as e:
logging.info('AGVToProduct error:%s' % e)
except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': str(e)}
logging.info('AGVDownProduct error:%s' % e)
return json.JSONEncoder().encode(res)
@http.route('/AutoDeviceApi/EquipmentBaseCoordinate', type='json', auth='sf_token', methods=['GET', 'POST'],
csrf=False,
cors="*")
def PutEquipmentBaseCoordinate(self, **kw):
"""
获取机床基坐标
:param kw:
:return:
"""
logging.info('PutEquipmentBaseCoordinate:%s' % kw)
try:
res = {'Succeed': True}
datas = request.httprequest.data
ret = json.loads(datas)
request.env['center_control.interface.log'].sudo().create(
{'content': ret, 'name': 'AutoDeviceApi/EquipmentBaseCoordinate'})
if 'DeviceId' in ret:
equipment = request.env['maintenance.equipment'].sudo().search('name', '=', ret['DeviceId'])
if equipment:
equipment.sudo().write({
'base_coordinate_fixture_model_id': ret['base_coordinate_fixture_model_id'],
'base_coordinate_g_coordinate': ret['base_coordinate_g_coordinate'],
'base_coordinate_x': ret['base_coordinate_x'],
'base_coordinate_y': ret['base_coordinate_y'],
'base_coordinate_z': ret['base_coordinate_z'],
})
else:
res = {'Succeed': False, 'ErrorCode': 203, 'Error': 'DeviceId为%s的设备不存在!' % ret['DeviceId']}
else:
res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传DeviceId字段'}
except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('AGVDownProduct error:%s' % e)
return json.JSONEncoder().encode(res)
@http.route('/AutoDeviceApi/AgvStationState', type='json', auth='public', methods=['GET', 'POST'], csrf=False,
cors="*")
def AGVStationState(self, **kw):
"""
中控推送接驳站状态
:param kw:
:return:
"""
logging.info('AGVStationState:%s' % kw)
try:
res = {'Succeed': True}
datas = request.httprequest.data
ret = json.loads(datas)
request.env['center_control.interface.log'].sudo().create(
{'content': ret, 'name': 'AutoDeviceApi/AGVStationState'})
logging.info('ret:%s' % ret)
ret = ret['param']
params = {}
for i in range(len(ret)):
if 'DeviceId' in ret[i] and 'AtHome' in ret[i]:
logging.info('DeviceId:%s, AtHome:%s' % (ret[i]['DeviceId'], ret[i]['AtHome']))
params[ret[i]['DeviceId']] = '占用' if ret[i]['AtHome'] else '空闲'
if params:
request.env['sf.agv.site'].update_site_state(params)
except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': str(e)}
logging.info('AGVDownProduct error:%s' % e)
return json.JSONEncoder().encode(res)