diff --git a/sf_manufacturing/controllers/controllers.py b/sf_manufacturing/controllers/controllers.py index ac7f77b3..b9027a9f 100644 --- a/sf_manufacturing/controllers/controllers.py +++ b/sf_manufacturing/controllers/controllers.py @@ -166,11 +166,13 @@ class Manufacturing_Connect(http.Controller): 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) @@ -457,20 +459,21 @@ class Manufacturing_Connect(http.Controller): rfid_code = ret[f'RfidCode{i}'] logging.info('RfidCode:%s' % rfid_code) domain = [ - ('feeder_station_destination_id.name', '=', ret['DeviceId']), - ('workorder_id.rfid_code', '=', rfid_code), - ('status', '=', '已配送'), - ('type', '=', '上产线') + ('rfid_code', '=', rfid_code), + ('routing_type', '=', 'CNC加工') ] - workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search(domain, - order='id asc') - if workpiece_delivery: - for wd in workpiece_delivery: - logging.info('wd.production_id:%s' % wd.production_id.name) - if wd.workorder_id.state == 'done' and wd.production_id.production_line_state == '待上产线': + workorder = request.env['mrp.workorder'].sudo().search(domain, order='id asc') + if workorder: + for order in workorder: + if order.production_id.production_line_state == '待上产线': logging.info( - 'wd.production_line_state:%s' % wd.production_id.production_line_state) - wd.production_id.write({'production_line_state': '已上产线'}) + '制造订单产线状态:%s' % order.production_id.production_line_state) + order.production_id.write({'production_line_state': '已上产线'}) + workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search([ + ('rfid_code', '=', rfid_code), ('type', '=', '上产线'), + ('production_id', '=', order.production_id.id)]) + if workpiece_delivery.status == '待下发': + workpiece_delivery.write({'is_manual_work': True}) else: res = {'Succeed': False, 'ErrorCode': 204, 'Error': 'DeviceId为%s没有对应的已配送工件数据' % ret['DeviceId']} @@ -511,20 +514,20 @@ class Manufacturing_Connect(http.Controller): rfid_code = ret[f'RfidCode{i}'] logging.info('RfidCode:%s' % rfid_code) domain = [ - ('workorder_id.rfid_code', '=', rfid_code), - ('status', '=', '待下发'), - ('type', '=', '下产线') + ('rfid_code', '=', rfid_code), + ('routing_type', '=', 'CNC加工') ] - workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search(domain, - order='id asc') - if workpiece_delivery: - for wd in workpiece_delivery: - logging.info('wd.production_id:%s' % wd.production_id.name) - if wd.workorder_id.state == 'done' and wd.production_id.production_line_state == '已上产线': + workorder = request.env['mrp.workorder'].sudo().search(domain, order='id asc') + if workorder: + for order in workorder: + if order.production_id.production_line_state == '已上产线': logging.info( - 'wd.production_line_state:%s' % wd.production_id.production_line_state) - wd.production_id.write({'production_line_state': '已下产线'}) - delivery_Arr.append(wd.id) + '制造订单产线状态:%s' % order.production_id.production_line_state) + order.production_id.write({'production_line_state': '已下产线'}) + workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search([ + ('rfid_code', '=', rfid_code), ('type', '=', '下产线'), + ('production_id', '=', order.production_id.id)]) + delivery_Arr.append(workpiece_delivery.id) else: res = {'Succeed': False, 'ErrorCode': 204, 'Error': 'DeviceId为%s没有对应的已配送工件数据' % ret['DeviceId']} @@ -534,10 +537,14 @@ class Manufacturing_Connect(http.Controller): [('id', 'in', delivery_Arr)]) if delivery_workpiece: logging.info('开始向agv下发下产线任务') - is_free = delivery_workpiece._check_avgsite_state() - if is_free is True: - delivery_workpiece._delivery_avg() - 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下发下产线任务下发完成') else: res = {'Succeed': False, 'ErrorCode': 203, 'Error': '未传IsComplete字段'} except Exception as e: