From 998900955d3e3ad6a4604953e8dff1268bc2b21f Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Fri, 23 Feb 2024 16:01:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B4=A8=E6=A3=80=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/controllers/controllers.py | 8 ++++--- sf_manufacturing/models/mrp_workorder.py | 25 +++++++++++---------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/sf_manufacturing/controllers/controllers.py b/sf_manufacturing/controllers/controllers.py index 63ca019a..c918a52a 100644 --- a/sf_manufacturing/controllers/controllers.py +++ b/sf_manufacturing/controllers/controllers.py @@ -217,10 +217,12 @@ class Manufacturing_Connect(http.Controller): [('production_id', '=', production_id), ('routing_type', '=', routing_type)], limit=1) if workorder: if 'ReportPaht' in ret: - download_state = request.env['mrp.workorder'].sudo().download_reportfile_tmp(workorder, - ret['ReportPaht']) + download_state = request.env['mrp.workorder'].with_user( + request.env.ref("base.user_admin")).download_reportfile_tmp(workorder, + ret['ReportPaht']) if download_state is not False: - request.env['mrp.workorder'].sudo().get_detection_file(workorder, ret['ReportPaht']) + request.env['mrp.workorder'].with_user( + request.env.ref("base.user_admin")).get_detection_file(workorder, ret['ReportPaht']) else: res = {'Succeed': False, 'ErrorCode': 204, 'Error': '检测报告文件从FTP拉取失败'} else: diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 931da029..a751d5ae 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -627,6 +627,19 @@ class ResMrpWorkOrder(models.Model): self.production_id.button_mark_done1() # self.production_id.state = 'done' + # 将FTP的检测报告文件下载到临时目录 + def download_reportfile_tmp(self, workorder, reportpath): + production_no = workorder.production_id.name.replace('/', '_') + remotepath = os.path.join('/', production_no, 'detection') + serverdir = os.path.join('/tmp', production_no, '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'], + ftp_resconfig['ftp_password']) + download_state = ftp.download_reportfile_tree(remotepath, serverdir, reportpath) + logging.info('download_state:%s' % download_state) + return download_state + class CNCprocessing(models.Model): _name = 'sf.cnc.processing' @@ -745,18 +758,6 @@ class CNCprocessing(models.Model): logging.info('download_state:%s' % download_state) return download_state - # 将FTP的检测报告文件下载到临时目录 - def download_reportfile_tmp(self, workorder, reportpath): - production_no = workorder.production_id.name.replace('/','_') - remotepath = os.path.join('/', production_no, 'detection') - serverdir = os.path.join('/tmp', production_no, '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'], - ftp_resconfig['ftp_password']) - download_state = ftp.download_reportfile_tree(remotepath, serverdir, reportpath) - logging.info('download_state:%s' % download_state) - return download_state - # 将nc文件存到attach的datas里 def write_file(self, nc_file_path, cnc): if os.path.exists(nc_file_path):