优化三次元检测报告
This commit is contained in:
@@ -260,38 +260,25 @@ 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:
|
||||
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 == 1:
|
||||
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'])
|
||||
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}
|
||||
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:
|
||||
|
||||
@@ -1205,38 +1205,28 @@ 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')
|
||||
logging.info('reportpath/ftp地址:%s' % reportpath)
|
||||
serverdir = os.path.join('/tmp', production_no_ftp[1], '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'])
|
||||
download_state = ftp.download_reportfile_tree(remotepath, serverdir, reportpath)
|
||||
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)
|
||||
else:
|
||||
download_state = 2
|
||||
return download_state
|
||||
|
||||
# 根据中控系统提供的检测文件地址去ftp里对应的制造订单里获取
|
||||
def get_detection_file(self, workorder, reportPath):
|
||||
# if reportPath.startswith('/'):
|
||||
# reportPath = reportPath[4:]
|
||||
# serverdir = os.path.join('/tmp', reportPath)
|
||||
if reportPath.startswith('/'):
|
||||
reportPath = reportPath[4:]
|
||||
serverdir = '/tmp' + reportPath
|
||||
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 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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user