修复编程单下发ftp路径

This commit is contained in:
jinling.yang
2024-06-26 11:10:54 +08:00
parent 1940116a35
commit 2ff935f68d
2 changed files with 10 additions and 11 deletions

View File

@@ -37,13 +37,13 @@ class Sf_Mrs_Connect(http.Controller):
for file_name in files_r: for file_name in files_r:
file_path = os.path.join(program_path_tmp_r, file_name) file_path = os.path.join(program_path_tmp_r, file_name)
os.remove(file_path) os.remove(file_path)
download_state = request.env['sf.cnc.processing'].with_user( download_state = request.env['sf.cnc.processing'].with_user(
request.env.ref("base.user_admin")).download_file_tmp( request.env.ref("base.user_admin")).download_file_tmp(
ret['folder_name'], r) ret['folder_name'], r)
if download_state == 0: if download_state == 0:
res['status'] = -2 res['status'] = -2
res['message'] = '编程单号为%s的CNC程序文件从FTP拉取失败' % (ret['programming_no']) res['message'] = '编程单号为%s的CNC程序文件从FTP拉取失败' % (ret['programming_no'])
return json.JSONEncoder().encode(res) return json.JSONEncoder().encode(res)
for production in productions: for production in productions:
if not production.workorder_ids: if not production.workorder_ids:
production.product_id.model_processing_panel = ret['processing_panel'] production.product_id.model_processing_panel = ret['processing_panel']

View File

@@ -32,11 +32,11 @@ class FtpController():
for directory in directories: for directory in directories:
if directory: if directory:
# 检查目录是否存在 # 检查目录是否存在
if directory in ['NC']: if (directory in ['NC']) or (directory not in ['home', 'ftp', 'ftp_root', 'NC']):
self.ftp.cwd(directory) self.ftp.cwd(directory)
if directory not in ['home', 'ftp', 'ftp_root', 'NC']: if directory not in ['home', 'ftp', 'ftp_root', 'NC']:
# 切换到新的目录 # 切换到新的目录
self.ftp.cwd(current_dir) self.ftp.cwd(directory)
return os.path.basename(path) return os.path.basename(path)
except Exception as e: except Exception as e:
logging.error(f"Error checking file: {e}") logging.error(f"Error checking file: {e}")
@@ -60,14 +60,13 @@ class FtpController():
try: try:
logging.info('FTP目录:%s' % target_dir) logging.info('FTP目录:%s' % target_dir)
logging.info("进入FTP目录 ") logging.info("进入FTP目录 ")
# self.ftp.cwd(target_dir) # 切换工作路径
# logging.info('FTP目录:%s' % target_dir)
remotenames = self.ftp.nlst() remotenames = self.ftp.nlst()
logging.info('FTP目录文件:%s' % remotenames) logging.info('FTP目录文件:%s' % remotenames)
for file in remotenames: for file in remotenames:
server = os.path.join(serverdir, file) server = os.path.join(serverdir, file)
if file.find(".pdf") != -1: if file.find(".pdf") != -1:
self.download_file(server, file) self.download_file(server, file)
return True
except: except:
return False return False