From 267667b3f5f95f56d85ca6d26a5c96ae3d7cc3ac Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Mon, 26 Feb 2024 16:34:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96cnc=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_workorder.py | 60 +++++++++++++---------- sf_mrs_connect/controllers/controllers.py | 11 +++-- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 06596db8..5b550958 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -683,32 +683,35 @@ class CNCprocessing(models.Model): program_path = fields.Char('程序文件路径') # mrs下发编程单创建CNC加工 - def cnc_processing_create(self, cnc_workorder, ret, program_path_ftp): + def cnc_processing_create(self, cnc_workorder, ret, program_path, program_path_tmp): logging.info('ret:%s' % ret) - logging.info('program_path_ftp:%s' % program_path_ftp) + logging.info('program_path_tmp:%s' % program_path_tmp) + logging.info('program_path:%s' % program_path) for obj in ret['programming_list']: workorder = self.env['mrp.workorder'].search([('production_id.name', '=', ret['production_order_no']), ('processing_panel', '=', obj['processing_panel']), ('routing_type', '=', 'CNC加工')]) - logging.info('workorder:%s' % workorder) + logging.info('workorder:%s' % workorder.name) logging.info('obj:%s' % obj) - cnc_processing = self.env['sf.cnc.processing'].create({ - 'workorder_id': workorder.id, - 'sequence_number': obj['sequence_number'], - 'program_name': obj['program_name'], - 'cutting_tool_name': obj['cutting_tool_name'], - 'cutting_tool_no': obj['cutting_tool_no'], - 'processing_type': obj['processing_type'], - 'margin_x_y': obj['margin_x_y'], - 'margin_z': obj['margin_z'], - 'depth_of_processing_z': obj['depth_of_processing_z'], - 'cutting_tool_extension_length': obj['cutting_tool_extension_length'], - 'cutting_tool_handle_type': obj['cutting_tool_handle_type'], - 'estimated_processing_time': obj['estimated_processing_time'], - 'remark': obj['remark'], - 'program_path': '%s/%s' % (program_path_ftp, obj['program_name']) - }) - cnc_processing.get_cnc_processing_file(ret['folder_name'], cnc_processing, workorder.processing_panel) + if obj['program_name'] in program_path: + logging.info('obj:%s' % obj['program_name']) + cnc_processing = self.env['sf.cnc.processing'].create({ + 'workorder_id': workorder.id, + 'sequence_number': obj['sequence_number'], + 'program_name': obj['program_name'], + 'cutting_tool_name': obj['cutting_tool_name'], + 'cutting_tool_no': obj['cutting_tool_no'], + 'processing_type': obj['processing_type'], + 'margin_x_y': obj['margin_x_y'], + 'margin_z': obj['margin_z'], + 'depth_of_processing_z': obj['depth_of_processing_z'], + 'cutting_tool_extension_length': obj['cutting_tool_extension_length'], + 'cutting_tool_handle_type': obj['cutting_tool_handle_type'], + 'estimated_processing_time': obj['estimated_processing_time'], + 'remark': obj['remark'], + 'program_path': program_path + }) + cnc_processing.get_cnc_processing_file(program_path_tmp, cnc_processing, program_path) # cnc_workorder.state = 'done' cnc_workorder.work_state = '已编程' cnc_workorder.programming_state = '已编程' @@ -716,9 +719,9 @@ class CNCprocessing(models.Model): # cnc_workorder.button_finish() # 根据程序名和加工面匹配到ftp里对应的Nc程序名 - def get_cnc_processing_file(self, folder_name, cnc_processing, processing_panel): - logging.info('folder_name:%s' % folder_name) - serverdir = os.path.join('/tmp', folder_name, 'return', processing_panel) + def get_cnc_processing_file(self, serverdir, cnc_processing, program_path): + # logging.info('program_path_tmp:%s' % program_path_tmp) + # serverdir = os.path.join('/tmp', folder_name, 'return', processing_panel) logging.info('serverdir:%s' % serverdir) for root, dirs, files in os.walk(serverdir): for f in files: @@ -731,13 +734,14 @@ class CNCprocessing(models.Model): cnc_processing.workorder_id.cnc_worksheet = base64.b64encode( open(full_path, 'rb').read()) else: - if cnc_processing.program_name == f.split('.')[0]: + if f in program_path: + # if cnc_processing.program_name == f.split('.')[0]: cnc_file_path = os.path.join(serverdir, root, f) logging.info('cnc_file_path:%s' % cnc_file_path) + logging.info('program_path:%s' % program_path) + logging.info('f:%s' % f) self.write_file(cnc_file_path, cnc_processing) - - # 创建附件(nc文件) def attachment_create(self, name, data): attachment = self.env['ir.attachment'].create({ @@ -762,10 +766,12 @@ class CNCprocessing(models.Model): # 将nc文件存到attach的datas里 def write_file(self, nc_file_path, cnc): + nc_file_name = nc_file_path.split('/') + logging.info('nc_file_name:%s' % nc_file_name[-1]) if os.path.exists(nc_file_path): with open(nc_file_path, 'rb') as file: data_bytes = file.read() - attachment = self.attachment_create(cnc.program_name + '.NC', data_bytes) + attachment = self.attachment_create(cnc.program_name + nc_file_name[-1], data_bytes) cnc.write({'cnc_id': attachment.id}) file.close() else: diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py index dee4c5f3..18381f3d 100644 --- a/sf_mrs_connect/controllers/controllers.py +++ b/sf_mrs_connect/controllers/controllers.py @@ -43,10 +43,13 @@ class Sf_Mrs_Connect(http.Controller): res['message'] = '制造订单号为%s的CNC程序文件从FTP拉取失败' % (cnc_production.name) return json.JSONEncoder().encode(res) logging.info('创建cnc工单') - program_path_ftp = os.path.join('/', ret['folder_name'], 'return', r) - logging.info('cnc程序路径 :%s' % program_path_ftp) - request.env['sf.cnc.processing'].with_user( - request.env.ref("base.user_admin")).cnc_processing_create(cnc_production, ret, program_path_ftp) + program_path_tmp = os.path.join('/tmp', ret['folder_name'], 'return', r) + files = os.listdir(program_path_tmp) + for f in files: + program_path = os.path.join(program_path_tmp, f) + logging.info('cnc程序路径 :%s' % program_path) + request.env['sf.cnc.processing'].with_user( + request.env.ref("base.user_admin")).cnc_processing_create(cnc_production, ret, program_path,program_path_tmp) return json.JSONEncoder().encode(res) else: res = {'status': 0, 'message': '该制造订单暂未开始'} From 2a39320fc3668284572b2f933971eb872c051021 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Mon, 26 Feb 2024 16:37:54 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96cnc?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=9A=84=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_workorder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 5b550958..1b2520cc 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -711,7 +711,7 @@ class CNCprocessing(models.Model): 'remark': obj['remark'], 'program_path': program_path }) - cnc_processing.get_cnc_processing_file(program_path_tmp, cnc_processing, program_path) + cnc_processing.get_cnc_processing_file(program_path_tmp, cnc_processing, program_path) # cnc_workorder.state = 'done' cnc_workorder.work_state = '已编程' cnc_workorder.programming_state = '已编程'