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):