优化cnc程序,
This commit is contained in:
@@ -683,15 +683,18 @@ class CNCprocessing(models.Model):
|
|||||||
program_path = fields.Char('程序文件路径')
|
program_path = fields.Char('程序文件路径')
|
||||||
|
|
||||||
# mrs下发编程单创建CNC加工
|
# 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('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']:
|
for obj in ret['programming_list']:
|
||||||
workorder = self.env['mrp.workorder'].search([('production_id.name', '=', ret['production_order_no']),
|
workorder = self.env['mrp.workorder'].search([('production_id.name', '=', ret['production_order_no']),
|
||||||
('processing_panel', '=', obj['processing_panel']),
|
('processing_panel', '=', obj['processing_panel']),
|
||||||
('routing_type', '=', 'CNC加工')])
|
('routing_type', '=', 'CNC加工')])
|
||||||
logging.info('workorder:%s' % workorder)
|
logging.info('workorder:%s' % workorder.name)
|
||||||
logging.info('obj:%s' % obj)
|
logging.info('obj:%s' % obj)
|
||||||
|
if obj['program_name'] in program_path:
|
||||||
|
logging.info('obj:%s' % obj['program_name'])
|
||||||
cnc_processing = self.env['sf.cnc.processing'].create({
|
cnc_processing = self.env['sf.cnc.processing'].create({
|
||||||
'workorder_id': workorder.id,
|
'workorder_id': workorder.id,
|
||||||
'sequence_number': obj['sequence_number'],
|
'sequence_number': obj['sequence_number'],
|
||||||
@@ -706,9 +709,9 @@ class CNCprocessing(models.Model):
|
|||||||
'cutting_tool_handle_type': obj['cutting_tool_handle_type'],
|
'cutting_tool_handle_type': obj['cutting_tool_handle_type'],
|
||||||
'estimated_processing_time': obj['estimated_processing_time'],
|
'estimated_processing_time': obj['estimated_processing_time'],
|
||||||
'remark': obj['remark'],
|
'remark': obj['remark'],
|
||||||
'program_path': '%s/%s' % (program_path_ftp, obj['program_name'])
|
'program_path': program_path
|
||||||
})
|
})
|
||||||
cnc_processing.get_cnc_processing_file(ret['folder_name'], cnc_processing, workorder.processing_panel)
|
cnc_processing.get_cnc_processing_file(program_path_tmp, cnc_processing, program_path)
|
||||||
# cnc_workorder.state = 'done'
|
# cnc_workorder.state = 'done'
|
||||||
cnc_workorder.work_state = '已编程'
|
cnc_workorder.work_state = '已编程'
|
||||||
cnc_workorder.programming_state = '已编程'
|
cnc_workorder.programming_state = '已编程'
|
||||||
@@ -716,9 +719,9 @@ class CNCprocessing(models.Model):
|
|||||||
# cnc_workorder.button_finish()
|
# cnc_workorder.button_finish()
|
||||||
|
|
||||||
# 根据程序名和加工面匹配到ftp里对应的Nc程序名
|
# 根据程序名和加工面匹配到ftp里对应的Nc程序名
|
||||||
def get_cnc_processing_file(self, folder_name, cnc_processing, processing_panel):
|
def get_cnc_processing_file(self, serverdir, cnc_processing, program_path):
|
||||||
logging.info('folder_name:%s' % folder_name)
|
# logging.info('program_path_tmp:%s' % program_path_tmp)
|
||||||
serverdir = os.path.join('/tmp', folder_name, 'return', processing_panel)
|
# serverdir = os.path.join('/tmp', folder_name, 'return', processing_panel)
|
||||||
logging.info('serverdir:%s' % serverdir)
|
logging.info('serverdir:%s' % serverdir)
|
||||||
for root, dirs, files in os.walk(serverdir):
|
for root, dirs, files in os.walk(serverdir):
|
||||||
for f in files:
|
for f in files:
|
||||||
@@ -731,13 +734,14 @@ class CNCprocessing(models.Model):
|
|||||||
cnc_processing.workorder_id.cnc_worksheet = base64.b64encode(
|
cnc_processing.workorder_id.cnc_worksheet = base64.b64encode(
|
||||||
open(full_path, 'rb').read())
|
open(full_path, 'rb').read())
|
||||||
else:
|
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)
|
cnc_file_path = os.path.join(serverdir, root, f)
|
||||||
logging.info('cnc_file_path:%s' % cnc_file_path)
|
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)
|
self.write_file(cnc_file_path, cnc_processing)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 创建附件(nc文件)
|
# 创建附件(nc文件)
|
||||||
def attachment_create(self, name, data):
|
def attachment_create(self, name, data):
|
||||||
attachment = self.env['ir.attachment'].create({
|
attachment = self.env['ir.attachment'].create({
|
||||||
@@ -762,10 +766,12 @@ class CNCprocessing(models.Model):
|
|||||||
|
|
||||||
# 将nc文件存到attach的datas里
|
# 将nc文件存到attach的datas里
|
||||||
def write_file(self, nc_file_path, cnc):
|
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):
|
if os.path.exists(nc_file_path):
|
||||||
with open(nc_file_path, 'rb') as file:
|
with open(nc_file_path, 'rb') as file:
|
||||||
data_bytes = file.read()
|
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})
|
cnc.write({'cnc_id': attachment.id})
|
||||||
file.close()
|
file.close()
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -43,10 +43,13 @@ class Sf_Mrs_Connect(http.Controller):
|
|||||||
res['message'] = '制造订单号为%s的CNC程序文件从FTP拉取失败' % (cnc_production.name)
|
res['message'] = '制造订单号为%s的CNC程序文件从FTP拉取失败' % (cnc_production.name)
|
||||||
return json.JSONEncoder().encode(res)
|
return json.JSONEncoder().encode(res)
|
||||||
logging.info('创建cnc工单')
|
logging.info('创建cnc工单')
|
||||||
program_path_ftp = os.path.join('/', ret['folder_name'], 'return', r)
|
program_path_tmp = os.path.join('/tmp', ret['folder_name'], 'return', r)
|
||||||
logging.info('cnc程序路径 :%s' % program_path_ftp)
|
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['sf.cnc.processing'].with_user(
|
||||||
request.env.ref("base.user_admin")).cnc_processing_create(cnc_production, ret, program_path_ftp)
|
request.env.ref("base.user_admin")).cnc_processing_create(cnc_production, ret, program_path,program_path_tmp)
|
||||||
return json.JSONEncoder().encode(res)
|
return json.JSONEncoder().encode(res)
|
||||||
else:
|
else:
|
||||||
res = {'status': 0, 'message': '该制造订单暂未开始'}
|
res = {'status': 0, 'message': '该制造订单暂未开始'}
|
||||||
|
|||||||
Reference in New Issue
Block a user