通过质检接口的质检文件路径获取

This commit is contained in:
jinling.yang
2024-02-23 15:29:21 +08:00
parent f015cbb9fd
commit 2e62915b41
4 changed files with 54 additions and 16 deletions

View File

@@ -139,14 +139,7 @@ class ResMrpWorkOrder(models.Model):
string='生产线', store=True)
production_line_state = fields.Selection(related='production_id.production_line_state',
string='上/下产线', store=True)
detection_report_path = fields.Char('检测报告链接地址')
# @api.onchange('rfid_code')
# def compute_rfid(self):
# workorder = self.env['mrp.workorder'].search([('production_id', '=', self.production_id.id)])
# if workorder:
# for item in workorder:
# item.write({'rfid_code': self.rfid_code})
detection_report = fields.Binary('检测报告', readonly=True)
def get_plan_workorder(self, production_line):
tomorrow = (date.today() + timedelta(days=+1)).strftime("%Y-%m-%d")
@@ -713,6 +706,23 @@ class CNCprocessing(models.Model):
logging.info('cnc_file_path:%s' % cnc_file_path)
self.write_file(cnc_file_path, cnc_processing)
# 根据中控系统提供的检测文件地址去ftp里对应的制造订单里获取
def get_detection_file(self, workorder, reportPath):
logging.info('workorder:%s' % workorder.name)
logging.info('制造订单:%s' % workorder.production_id.name)
logging.info('reportPath:%s' % reportPath)
serverdir = os.path.join('/tmp', reportPath).replace('//', '/')
logging.info('serverdir:%s' % serverdir)
for root, dirs, files in os.walk(serverdir):
for f in files:
logging.info('f:%s' % f)
if os.path.splitext(f)[1] == ".pdf":
full_path = os.path.join(serverdir, root, f)
logging.info('检测文件路径:%s' % full_path)
if full_path is not False:
workorder.detection_report = base64.b64encode(
open(full_path, 'rb').read())
# 创建附件(nc文件)
def attachment_create(self, name, data):
attachment = self.env['ir.attachment'].create({
@@ -735,6 +745,18 @@ 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):