From 40f327ea1745437cdf1dac3844c5f078c0146662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Tue, 10 Sep 2024 16:13:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B7=A5=E4=BB=B6=E6=8B=86?= =?UTF-8?q?=E5=8D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/controllers/controllers.py | 6 +- sf_manufacturing/models/agv_scheduling.py | 1 + sf_manufacturing/models/mrp_workorder.py | 38 +++--- .../wizard/workpiece_delivery_wizard.py | 16 ++- sf_mrs_connect/controllers/controllers.py | 112 +++++++++--------- 5 files changed, 91 insertions(+), 82 deletions(-) diff --git a/sf_manufacturing/controllers/controllers.py b/sf_manufacturing/controllers/controllers.py index 632e9e4c..c249eda2 100644 --- a/sf_manufacturing/controllers/controllers.py +++ b/sf_manufacturing/controllers/controllers.py @@ -477,7 +477,7 @@ class Manufacturing_Connect(http.Controller): logging.info('LocationChange error:%s' % e) return json.JSONEncoder().encode(res) - @http.route('/AutoDeviceApi/AGVToProduct', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False, + @http.route('/AutoDeviceApi/AGVToProduct', type='json', auth='public', methods=['GET', 'POST'], csrf=False, cors="*") def AGVToProduct(self, **kw): """ @@ -549,7 +549,7 @@ class Manufacturing_Connect(http.Controller): logging.info('AGVToProduct error:%s' % e) return json.JSONEncoder().encode(res) - @http.route('/AutoDeviceApi/AGVDownProduct', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False, + @http.route('/AutoDeviceApi/AGVDownProduct', type='json', auth='public', methods=['GET', 'POST'], csrf=False, cors="*") def AGVDownProduct(self, **kw): """ @@ -668,7 +668,7 @@ class Manufacturing_Connect(http.Controller): logging.info('AGVDownProduct error:%s' % e) return json.JSONEncoder().encode(res) - @http.route('/AutoDeviceApi/AgvStationState', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False, + @http.route('/AutoDeviceApi/AgvStationState', type='json', auth='public', methods=['GET', 'POST'], csrf=False, cors="*") def AGVStationState(self, **kw): """ diff --git a/sf_manufacturing/models/agv_scheduling.py b/sf_manufacturing/models/agv_scheduling.py index 488fa0a0..f758abd9 100644 --- a/sf_manufacturing/models/agv_scheduling.py +++ b/sf_manufacturing/models/agv_scheduling.py @@ -270,6 +270,7 @@ class ResMrpWorkOrder(models.Model): """ 获取关联的制造订单下产线的agv任务 """ + self.ensure_one() workorder_ids = self.production_id.workorder_ids cnc_workorder = workorder_ids.filtered( lambda w: w.routing_type == 'CNC加工' and w.state == 'done' and w.processing_panel == self.processing_panel diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 976097e3..28f10ab4 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -1351,23 +1351,23 @@ class ResMrpWorkOrder(models.Model): return res def button_delivery(self): - production_ids = [] - workorder_ids = [] + # production_ids = [] + # workorder_ids = [] delivery_type = '运送空料架' - max_num = 4 # 最大配送数量 - feeder_station_start_id = False - if len(self) > max_num: - raise UserError('仅限于拆卸1-4个制造订单,请重新选择') - for item in self: - if item.state != 'ready': - raise UserError('请选择状态为【就绪】的工单进行解除装夹') - - production_ids.append(item.production_id.id) - workorder_ids.append(item.id) - if not feeder_station_start_id: - down_product_agv_scheduling = self.get_down_product_agv_scheduling() - if down_product_agv_scheduling: - feeder_station_start_id = down_product_agv_scheduling.end_site_id.id + # max_num = 4 # 最大配送数量 + # feeder_station_start_id = False + # if len(self) > max_num: + # raise UserError('仅限于拆卸1-4个制造订单,请重新选择') + # for item in self: + # if item.state != 'ready': + # raise UserError('请选择状态为【就绪】的工单进行解除装夹') + # + # production_ids.append(item.production_id.id) + # workorder_ids.append(item.id) + # if not feeder_station_start_id: + # down_product_agv_scheduling = item.get_down_product_agv_scheduling() + # if down_product_agv_scheduling: + # feeder_station_start_id = down_product_agv_scheduling.end_site_id.id return { 'name': _('确认'), 'type': 'ir.actions.act_window', @@ -1376,12 +1376,12 @@ class ResMrpWorkOrder(models.Model): 'target': 'new', 'context': { # 'default_delivery_ids': [(6, 0, delivery_ids)], - 'default_production_ids': [(6, 0, production_ids)], + # 'default_production_ids': [(6, 0, production_ids)], 'default_delivery_type': delivery_type, - 'default_workorder_ids': [(6, 0, workorder_ids)], + # 'default_workorder_ids': [(6, 0, workorder_ids)], 'default_workcenter_id': self.env.context.get('default_workcenter_id'), 'default_confirm_button': '确认解除', - 'default_feeder_station_start_id': feeder_station_start_id, + # 'default_feeder_station_start_id': feeder_station_start_id, }} diff --git a/sf_manufacturing/wizard/workpiece_delivery_wizard.py b/sf_manufacturing/wizard/workpiece_delivery_wizard.py index f00ac499..4645d45f 100644 --- a/sf_manufacturing/wizard/workpiece_delivery_wizard.py +++ b/sf_manufacturing/wizard/workpiece_delivery_wizard.py @@ -185,7 +185,11 @@ class WorkpieceDeliveryWizard(models.TransientModel): # 判断是否是AGV接驳站名称 agv_site = self.env['sf.agv.site'].search([('name', '=', barcode)]) if agv_site: - self.feeder_station_start_id = agv_site.id + if not self.feeder_station_start_id: + self.feeder_station_start_id = agv_site.id + else: + if self.feeder_station_start_id.id != agv_site.id: + raise UserError('接驳站不匹配!') return delivery_type = self.env.context.get('default_delivery_type') if delivery_type == '上产线': @@ -211,10 +215,14 @@ class WorkpieceDeliveryWizard(models.TransientModel): self.production_ids |= workorder.production_id self.workorder_ids |= workorder - if not self.feeder_station_start_id: - down_product_agv_scheduling = self.get_down_product_agv_scheduling() - if down_product_agv_scheduling: + down_product_agv_scheduling = self.get_down_product_agv_scheduling() + if down_product_agv_scheduling: + if not self.feeder_station_start_id: self.feeder_station_start_id = down_product_agv_scheduling.end_site_id.id + else: + if self.feeder_station_start_id.id != down_product_agv_scheduling.end_site_id.id: + raise UserError('该rfid不在%s接驳站内', self.feeder_station_start_id.name) + else: raise UserError('该rfid码对应的工单不存在') return diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py index c5d1cd10..25736199 100644 --- a/sf_mrs_connect/controllers/controllers.py +++ b/sf_mrs_connect/controllers/controllers.py @@ -31,67 +31,67 @@ class Sf_Mrs_Connect(http.Controller): request.env.ref("base.user_admin")).search(domain) if productions: # 拉取所有加工面的程序文件 - for r in ret['processing_panel'].split(','): - program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', r) - if os.path.exists(program_path_tmp_r): - files_r = os.listdir(program_path_tmp_r) - if files_r: - for file_name in files_r: - file_path = os.path.join(program_path_tmp_r, file_name) - os.remove(file_path) - download_state = request.env['sf.cnc.processing'].with_user( - request.env.ref("base.user_admin")).download_file_tmp( - ret['folder_name'], r) - if download_state is False: - res['status'] = -2 - res['message'] = '编程单号为%s的CNC程序文件从FTP拉取失败' % (ret['programming_no']) - return json.JSONEncoder().encode(res) + # for r in ret['processing_panel'].split(','): + # program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', r) + # if os.path.exists(program_path_tmp_r): + # files_r = os.listdir(program_path_tmp_r) + # if files_r: + # for file_name in files_r: + # file_path = os.path.join(program_path_tmp_r, file_name) + # os.remove(file_path) + # download_state = request.env['sf.cnc.processing'].with_user( + # request.env.ref("base.user_admin")).download_file_tmp( + # ret['folder_name'], r) + # if download_state is False: + # res['status'] = -2 + # res['message'] = '编程单号为%s的CNC程序文件从FTP拉取失败' % (ret['programming_no']) + # return json.JSONEncoder().encode(res) for production in productions: if not production.workorder_ids: production.product_id.model_processing_panel = ret['processing_panel'] production._create_workorder(ret) productions.process_range_time() - else: - for panel in ret['processing_panel'].split(','): - # 查询状态为进行中且工序类型为CNC加工的工单 - cnc_workorder_has = production.workorder_ids.filtered( - lambda ach: ach.routing_type == 'CNC加工' and ach.state not in ['progress', 'done', - 'rework', - 'cancel'] and ach.processing_panel == panel) - if cnc_workorder_has: - if cnc_workorder_has.cnc_ids: - cnc_workorder_has.cmm_ids.sudo().unlink() - cnc_workorder_has.cnc_ids.sudo().unlink() - request.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan( - production) - cnc_workorder_has.write( - {'cnc_ids': cnc_workorder_has.cnc_ids.sudo()._json_cnc_processing(panel, ret), - 'cmm_ids': cnc_workorder_has.cmm_ids.sudo()._json_cmm_program(panel, ret)}) - for panel in ret['processing_panel'].split(','): - # 查询状态为进行中且工序类型为CNC加工的工单 - cnc_workorder = productions.workorder_ids.filtered( - lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done', 'rework' - 'cancel'] and ac.processing_panel == panel) - if cnc_workorder: - # program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', - # panel) - program_path_tmp_panel = os.path.join('/tmp', ret['folder_name'], 'return', panel) - logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel) - files_panel = os.listdir(program_path_tmp_panel) - if files_panel: - for file in files_panel: - file_extension = os.path.splitext(file)[1] - logging.info('file_extension:%s' % file_extension) - if file_extension.lower() == '.pdf': - panel_file_path = os.path.join(program_path_tmp_panel, file) - logging.info('panel_file_path:%s' % panel_file_path) - cnc_workorder.write({'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())}) - pre_workorder = productions.workorder_ids.filtered( - lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done', 'rework' - 'cancel'] and ap.processing_panel == panel) - if pre_workorder: - pre_workorder.write( - {'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())}) + # else: + # for panel in ret['processing_panel'].split(','): + # # 查询状态为进行中且工序类型为CNC加工的工单 + # cnc_workorder_has = production.workorder_ids.filtered( + # lambda ach: ach.routing_type == 'CNC加工' and ach.state not in ['progress', 'done', + # 'rework', + # 'cancel'] and ach.processing_panel == panel) + # if cnc_workorder_has: + # if cnc_workorder_has.cnc_ids: + # cnc_workorder_has.cmm_ids.sudo().unlink() + # cnc_workorder_has.cnc_ids.sudo().unlink() + # request.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan( + # production) + # cnc_workorder_has.write( + # {'cnc_ids': cnc_workorder_has.cnc_ids.sudo()._json_cnc_processing(panel, ret), + # 'cmm_ids': cnc_workorder_has.cmm_ids.sudo()._json_cmm_program(panel, ret)}) + # for panel in ret['processing_panel'].split(','): + # # 查询状态为进行中且工序类型为CNC加工的工单 + # cnc_workorder = productions.workorder_ids.filtered( + # lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done', 'rework' + # 'cancel'] and ac.processing_panel == panel) + # if cnc_workorder: + # # program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', + # # panel) + # program_path_tmp_panel = os.path.join('/tmp', ret['folder_name'], 'return', panel) + # logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel) + # files_panel = os.listdir(program_path_tmp_panel) + # if files_panel: + # for file in files_panel: + # file_extension = os.path.splitext(file)[1] + # logging.info('file_extension:%s' % file_extension) + # if file_extension.lower() == '.pdf': + # panel_file_path = os.path.join(program_path_tmp_panel, file) + # logging.info('panel_file_path:%s' % panel_file_path) + # cnc_workorder.write({'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())}) + # pre_workorder = productions.workorder_ids.filtered( + # lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done', 'rework' + # 'cancel'] and ap.processing_panel == panel) + # if pre_workorder: + # pre_workorder.write( + # {'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())}) productions.write({'programming_state': '已编程', 'work_state': '已编程'}) return json.JSONEncoder().encode(res) else: