Merge branch 'feature/优化三次元检测报告' into develop

This commit is contained in:
jinling.yang
2024-07-31 11:55:46 +08:00
3 changed files with 31 additions and 55 deletions

View File

@@ -260,40 +260,27 @@ class Manufacturing_Connect(http.Controller):
request.env['center_control.interface.log'].sudo().create(
{'content': ret, 'name': 'AutoDeviceApi/PartQualityInspect'})
production_id = ret['BillId']
routing_type = ret['CraftId']
# routing_type = ret['CraftId']
workorder = request.env['mrp.workorder'].sudo().search(
[('production_id', '=', production_id), ('routing_type', '=', routing_type), ('state', '!=', 'rework')],
[('production_id', '=', production_id), ('routing_type', '=', 'CNC加工'),
('state', 'not in', ['rework', 'done', 'cancel'])], order='sequence asc',
limit=1)
if workorder:
# workorder.test_results = ret['Quality']
logging.info('制造订单:%s' % workorder.production_id.name)
if 'ReportPaht' in ret:
download_state = request.env['mrp.workorder'].with_user(
request.env.ref("base.user_admin")).download_reportfile_tmp(workorder,
ret['ReportPaht'])
if download_state == 1:
detection_ret = request.env['mrp.workorder'].with_user(
request.env.ref("base.user_admin")).get_detection_file(workorder, ret['ReportPaht'])
if detection_ret is True:
stock_picking_type = request.env['stock.picking.type'].sudo().search(
[('sequence_code', '=', 'SFP')])
if stock_picking_type:
stock_picking = request.env['stock.picking'].sudo().search(
[('product_id', '=', workorder.product_id.id),
('origin', '=', workorder.production_id.origin),
('picking_type_id', '=', stock_picking_type.id)])
if stock_picking:
quality_check = request.env['quality.check'].sudo().search(
[('product_id', '=', workorder.product_id.id),
('picking_id', '=', stock_picking.id)])
if quality_check:
logging.info('质检单:%s' % quality_check.name)
quality_check.write({'report_pdf': workorder.detection_report})
elif download_state == 2:
res = {'Succeed': False, 'ErrorCode': 205,
'Error': 'ReportPaht中的工件号与制造订单%s不匹配请检查ReportPaht是否正确' % workorder.production_id.name}
else:
res = {'Succeed': False, 'ErrorCode': 204, 'Error': '检测报告文件从FTP拉取失败'}
if ret['ReportPaht'].find('.pdf') != -1:
download_state = request.env['mrp.workorder'].with_user(
request.env.ref("base.user_admin")).download_reportfile_tmp(workorder,
ret['ReportPaht'])
if download_state is True:
detection_ret = request.env['mrp.workorder'].with_user(
request.env.ref("base.user_admin")).get_detection_file(workorder, ret['ReportPaht'])
logging.info('detection_ret:%s' % detection_ret)
if detection_ret is False:
res = {'Succeed': False, 'ErrorCode': 205, 'Error': '检测报告文件读取失败'}
else:
res = {'Succeed': False, 'ErrorCode': 204, 'Error': '检测报告文件从FTP拉取失败'}
else:
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '未传ReportPaht字段'}
else:

View File

@@ -1208,38 +1208,27 @@ class ResMrpWorkOrder(models.Model):
# 将FTP的检测报告文件下载到临时目录
def download_reportfile_tmp(self, workorder, reportpath):
logging.info('reportpath:%s' % reportpath)
production_no_ftp = reportpath.split('/')
production_no = workorder.production_id.name.replace('/', '_')
# ftp地址
remotepath = os.path.join('/NC', production_no_ftp[1], 'detection')
logging.info('ftp地址:%s' % remotepath)
if reportpath.find(production_no) != -1:
# 服务器内临时地址
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'],
ftp_resconfig['ftp_password'])
download_state = ftp.download_reportfile_tree(remotepath, serverdir, reportpath)
logging.info('download_state:%s' % download_state)
else:
download_state = 2
logging.info('reportpath/ftp地址:%s' % reportpath)
logging.info('processing_panel:%s' % workorder.processing_panel)
serverdir = os.path.join('/tmp', workorder.production_id.name.replace('/', '_'), 'detection',
workorder.processing_panel)
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'])
if not ftp.file_exists_1(reportpath):
logging.info('文件不存在:%s' % reportpath)
download_state = ftp.download_program_file(reportpath, serverdir)
logging.info('download_state:%s' % download_state)
return download_state
# 根据中控系统提供的检测文件地址去ftp里对应的制造订单里获取
def get_detection_file(self, workorder, reportPath):
# if reportPath.startswith('/'):
# reportPath = reportPath[4:]
# serverdir = os.path.join('/tmp', reportPath)
serverdir = '/tmp' + reportPath
serverdir = os.path.join('/tmp', workorder.production_id.name.replace('/', '_'), 'detection',
workorder.processing_panel)
logging.info('get_detection_file-serverdir:%s' % serverdir)
serverdir_prefix = os.path.dirname(serverdir)
logging.info('serverdir_prefix-serverdir:%s' % serverdir_prefix)
for root, dirs, files in os.walk(serverdir_prefix):
for root, dirs, files in os.walk(serverdir):
for filename in files:
logging.info('filename:%s' % filename)
logging.info('reportPath:%s' % os.path.basename(reportPath))
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)

View File

@@ -49,7 +49,7 @@ class FtpController():
logging.error(f"Error checking file: {e}")
return False
# 下载目录下的pdf文件(程序单)
# 下载目录下的pdf文件(程序单/检测文件)
def download_program_file(self, target_dir, serverdir):
if not os.path.exists(serverdir):
os.makedirs(serverdir)