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