优化cnc程序,

This commit is contained in:
jinling.yang
2024-02-26 16:34:26 +08:00
parent dbdc2e1238
commit 267667b3f5
2 changed files with 40 additions and 31 deletions

View File

@@ -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:

View File

@@ -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': '该制造订单暂未开始'}