修复质检接口
This commit is contained in:
@@ -631,13 +631,14 @@ class ResMrpWorkOrder(models.Model):
|
||||
# 将FTP的检测报告文件下载到临时目录
|
||||
def download_reportfile_tmp(self, workorder, reportpath):
|
||||
logging.info('reportpath:%s' % reportpath)
|
||||
production_no = reportpath.split('/')
|
||||
production_no_ftp = reportpath.split('/')
|
||||
production_no = workorder.production_id.name.replace('/', '_')
|
||||
# ftp地址
|
||||
remotepath = os.path.join('/', production_no[1], 'detection')
|
||||
remotepath = os.path.join('/', production_no_ftp[1], 'detection')
|
||||
logging.info('ftp地址:%s' % remotepath)
|
||||
if remotepath in reportpath:
|
||||
if reportpath.find(production_no) != -1:
|
||||
# 服务器内临时地址
|
||||
serverdir = os.path.join('/tmp', production_no, 'detection')
|
||||
serverdir = os.path.join('/tmp', production_no_ftp[1], 'detection')
|
||||
ftp_resconfig = self.env['res.config.settings'].get_values()
|
||||
ftp = FtpController(str(ftp_resconfig['ftp_host']), int(ftp_resconfig['ftp_port']),
|
||||
ftp_resconfig['ftp_user'],
|
||||
@@ -650,13 +651,16 @@ class ResMrpWorkOrder(models.Model):
|
||||
|
||||
# 根据中控系统提供的检测文件地址去ftp里对应的制造订单里获取
|
||||
def get_detection_file(self, workorder, reportPath):
|
||||
serverdir = os.path.join('/tmp', reportPath).replace('//', '/')
|
||||
if reportPath.startswith('/'):
|
||||
reportPath = reportPath[1:]
|
||||
serverdir = os.path.join('/tmp', reportPath)
|
||||
logging.info('get_detection_file-serverdir:%s' % serverdir)
|
||||
for root, dirs, files in os.walk(serverdir):
|
||||
for f in files:
|
||||
if f in reportPath:
|
||||
workorder.detection_report = base64.b64encode(
|
||||
open(serverdir, 'rb').read())
|
||||
for filename in files:
|
||||
if filename == os.path.basename(reportPath):
|
||||
report_file_path = os.path.join(root, filename)
|
||||
logging.info('get_detection_file-report_file_path:%s' % report_file_path)
|
||||
workorder.detection_report = base64.b64encode(open(report_file_path, 'rb').read())
|
||||
return True
|
||||
|
||||
|
||||
|
||||
@@ -49,15 +49,15 @@ class FtpController():
|
||||
target_dir1 = target_dir.split('/')
|
||||
logging.info('目录1:%s' % target_dir1[1])
|
||||
self.ftp.cwd(target_dir1[1]) # 切换工作路径
|
||||
logging.info('目录2:%s' % target_dir[2])
|
||||
self.ftp.cwd(target_dir[2]) # 切换工作路径
|
||||
logging.info('目录2:%s' % target_dir1[2])
|
||||
self.ftp.cwd(target_dir1[2]) # 切换工作路径
|
||||
remotenames = self.ftp.nlst()
|
||||
logging.info('FTP目录检测报告文件:%s' % remotenames)
|
||||
for file in remotenames:
|
||||
server = os.path.join(serverdir, file)
|
||||
if file.find(reportpath) != -1:
|
||||
logging.info('server' % server)
|
||||
self.download_file(server, file)
|
||||
for filename in remotenames:
|
||||
if os.path.basename(filename) == os.path.basename(reportpath):
|
||||
server = os.path.join(serverdir, filename)
|
||||
logging.info('server%s' % server)
|
||||
self.download_file(server, filename)
|
||||
return 1
|
||||
except Exception:
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user