合并工单优化

This commit is contained in:
gqh
2023-01-11 11:13:52 +08:00
parent 01cf30b03f
commit eb162cb416
17 changed files with 350 additions and 386 deletions

View File

@@ -20,32 +20,44 @@ class Sf_Mrs_Connect(http.Controller):
"""
logging.info('get_cnc_processing_create:%s' % kw)
try:
res = {'status': 1, 'message': '成功'}
datas = request.httprequest.data
ret = json.loads(datas)
ret = json.loads(ret['result'])
# 查询状态为进行中且类型为获取CNC加工程序的工单
cnc_workorder = request.env['mrp.workorder'].with_user(
request.env.ref("base.user_admin")).search([('production_id.name', '=', ret['production_order_no']),
('routing_type', '=', '获取CNC加工程序')])
if cnc_workorder:
# 拉取所有加工面的程序文件
# i = 1
for r in ret['processing_panel']:
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 == False:
res['status'] = -2
res['message'] = '制造订单号为%s的CNC程序文件从FTP拉取失败' % (cnc_workorder.production_id.name)
return json.JSONEncoder().encode(res)
request.env['sf.cnc.processing'].with_user(
request.env.ref("base.user_admin")).cnc_processing_create(cnc_workorder, ret)
return json.JSONEncoder().encode(res)
else:
res = {'status': 0, 'message': '该制造订单暂未开始'}
return json.JSONEncoder().encode(res)
for obj in ret:
cnc = request.env['sf.cnc.processing'].with_user(
request.env.ref("base.user_admin")).cnc_processing_create(obj)
# # 从ftp拉取对应的文件
model_code = cnc.workorder_id.product_id.barcode
processing_panel = cnc.workorder_id.processing_panel
logging.info('model_code:%s' % model_code)
server_dir = cnc.with_user(request.env.ref("base.user_admin")).download_file_tmp(model_code,
processing_panel)
# cnc_file_path = os.path.join('/', server_dir, cnc.program_name + '.nc')
# logging.info('cnc_file_path:%s' % cnc_file_path)
# cnc.with_user(request.env.ref("base.user_admin")).write_file(cnc_file_path, cnc)
logging.info('server_dir:%s' % server_dir)
for root, dirs, files in os.walk(server_dir):
for f in files:
logging.info('f:%s' % f)
logging.info('f[0]:%s' % f.split('.')[0])
if os.path.splitext(f)[1] == ".pdf":
full_path = os.path.join(server_dir, root, f)
logging.info('pdf:%s' % full_path)
if full_path != False:
if not cnc.workorder_id.cnc_worksheet:
cnc.workorder_id.cnc_worksheet = base64.b64encode(open(full_path, 'rb').read())
else:
logging.info('break:%s' % 'break')
continue
else:
logging.info('cnc.program_name:%s' % cnc.program_name)
if cnc.program_name == f.split('.')[0]:
logging.info('f[0]:%s' % f[0])
cnc_file_path = os.path.join(server_dir, root, f)
logging.info('cnc_file_path:%s' % cnc_file_path)
cnc.with_user(request.env.ref("base.user_admin")).write_file(cnc_file_path, cnc)
else:
continue
except Exception as e:
res = {'status': -1, 'message': '系统解析失败'}
logging.info('get_cnc_processing_create error:%s' % e)
return json.JSONEncoder().encode(res)