Merge branch 'feature/优化三次元检测报告' into develop
This commit is contained in:
@@ -260,40 +260,27 @@ class Manufacturing_Connect(http.Controller):
|
|||||||
request.env['center_control.interface.log'].sudo().create(
|
request.env['center_control.interface.log'].sudo().create(
|
||||||
{'content': ret, 'name': 'AutoDeviceApi/PartQualityInspect'})
|
{'content': ret, 'name': 'AutoDeviceApi/PartQualityInspect'})
|
||||||
production_id = ret['BillId']
|
production_id = ret['BillId']
|
||||||
routing_type = ret['CraftId']
|
# routing_type = ret['CraftId']
|
||||||
workorder = request.env['mrp.workorder'].sudo().search(
|
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)
|
limit=1)
|
||||||
if workorder:
|
if workorder:
|
||||||
# workorder.test_results = ret['Quality']
|
# workorder.test_results = ret['Quality']
|
||||||
logging.info('制造订单:%s' % workorder.production_id.name)
|
logging.info('制造订单:%s' % workorder.production_id.name)
|
||||||
if 'ReportPaht' in ret:
|
if 'ReportPaht' in ret:
|
||||||
download_state = request.env['mrp.workorder'].with_user(
|
if ret['ReportPaht'].find('.pdf') != -1:
|
||||||
request.env.ref("base.user_admin")).download_reportfile_tmp(workorder,
|
download_state = request.env['mrp.workorder'].with_user(
|
||||||
ret['ReportPaht'])
|
request.env.ref("base.user_admin")).download_reportfile_tmp(workorder,
|
||||||
if download_state == 1:
|
ret['ReportPaht'])
|
||||||
detection_ret = request.env['mrp.workorder'].with_user(
|
if download_state is True:
|
||||||
request.env.ref("base.user_admin")).get_detection_file(workorder, ret['ReportPaht'])
|
detection_ret = request.env['mrp.workorder'].with_user(
|
||||||
if detection_ret is True:
|
request.env.ref("base.user_admin")).get_detection_file(workorder, ret['ReportPaht'])
|
||||||
stock_picking_type = request.env['stock.picking.type'].sudo().search(
|
logging.info('detection_ret:%s' % detection_ret)
|
||||||
[('sequence_code', '=', 'SFP')])
|
if detection_ret is False:
|
||||||
if stock_picking_type:
|
res = {'Succeed': False, 'ErrorCode': 205, 'Error': '检测报告文件读取失败'}
|
||||||
stock_picking = request.env['stock.picking'].sudo().search(
|
else:
|
||||||
[('product_id', '=', workorder.product_id.id),
|
res = {'Succeed': False, 'ErrorCode': 204, 'Error': '检测报告文件从FTP拉取失败'}
|
||||||
('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拉取失败'}
|
|
||||||
else:
|
else:
|
||||||
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '未传ReportPaht字段'}
|
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '未传ReportPaht字段'}
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -1208,38 +1208,27 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
|
|
||||||
# 将FTP的检测报告文件下载到临时目录
|
# 将FTP的检测报告文件下载到临时目录
|
||||||
def download_reportfile_tmp(self, workorder, reportpath):
|
def download_reportfile_tmp(self, workorder, reportpath):
|
||||||
logging.info('reportpath:%s' % reportpath)
|
logging.info('reportpath/ftp地址:%s' % reportpath)
|
||||||
production_no_ftp = reportpath.split('/')
|
logging.info('processing_panel:%s' % workorder.processing_panel)
|
||||||
production_no = workorder.production_id.name.replace('/', '_')
|
serverdir = os.path.join('/tmp', workorder.production_id.name.replace('/', '_'), 'detection',
|
||||||
# ftp地址
|
workorder.processing_panel)
|
||||||
remotepath = os.path.join('/NC', production_no_ftp[1], 'detection')
|
ftp_resconfig = self.env['res.config.settings'].get_values()
|
||||||
logging.info('ftp地址:%s' % remotepath)
|
ftp = FtpController(str(ftp_resconfig['ftp_host']), int(ftp_resconfig['ftp_port']),
|
||||||
if reportpath.find(production_no) != -1:
|
ftp_resconfig['ftp_user'],
|
||||||
# 服务器内临时地址
|
ftp_resconfig['ftp_password'])
|
||||||
serverdir = os.path.join('/tmp', production_no_ftp[1], 'detection')
|
if not ftp.file_exists_1(reportpath):
|
||||||
ftp_resconfig = self.env['res.config.settings'].get_values()
|
logging.info('文件不存在:%s' % reportpath)
|
||||||
ftp = FtpController(str(ftp_resconfig['ftp_host']), int(ftp_resconfig['ftp_port']),
|
download_state = ftp.download_program_file(reportpath, serverdir)
|
||||||
ftp_resconfig['ftp_user'],
|
logging.info('download_state:%s' % download_state)
|
||||||
ftp_resconfig['ftp_password'])
|
|
||||||
download_state = ftp.download_reportfile_tree(remotepath, serverdir, reportpath)
|
|
||||||
logging.info('download_state:%s' % download_state)
|
|
||||||
else:
|
|
||||||
download_state = 2
|
|
||||||
return download_state
|
return download_state
|
||||||
|
|
||||||
# 根据中控系统提供的检测文件地址去ftp里对应的制造订单里获取
|
# 根据中控系统提供的检测文件地址去ftp里对应的制造订单里获取
|
||||||
def get_detection_file(self, workorder, reportPath):
|
def get_detection_file(self, workorder, reportPath):
|
||||||
# if reportPath.startswith('/'):
|
serverdir = os.path.join('/tmp', workorder.production_id.name.replace('/', '_'), 'detection',
|
||||||
# reportPath = reportPath[4:]
|
workorder.processing_panel)
|
||||||
# serverdir = os.path.join('/tmp', reportPath)
|
|
||||||
serverdir = '/tmp' + reportPath
|
|
||||||
logging.info('get_detection_file-serverdir:%s' % serverdir)
|
logging.info('get_detection_file-serverdir:%s' % serverdir)
|
||||||
serverdir_prefix = os.path.dirname(serverdir)
|
for root, dirs, files in os.walk(serverdir):
|
||||||
logging.info('serverdir_prefix-serverdir:%s' % serverdir_prefix)
|
|
||||||
for root, dirs, files in os.walk(serverdir_prefix):
|
|
||||||
for filename in files:
|
for filename in files:
|
||||||
logging.info('filename:%s' % filename)
|
|
||||||
logging.info('reportPath:%s' % os.path.basename(reportPath))
|
|
||||||
if filename == os.path.basename(reportPath):
|
if filename == os.path.basename(reportPath):
|
||||||
report_file_path = os.path.join(root, filename)
|
report_file_path = os.path.join(root, filename)
|
||||||
logging.info('get_detection_file-report_file_path:%s' % report_file_path)
|
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}")
|
logging.error(f"Error checking file: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# 下载目录下的pdf文件(程序单)
|
# 下载目录下的pdf文件(程序单/检测文件)
|
||||||
def download_program_file(self, target_dir, serverdir):
|
def download_program_file(self, target_dir, serverdir):
|
||||||
if not os.path.exists(serverdir):
|
if not os.path.exists(serverdir):
|
||||||
os.makedirs(serverdir)
|
os.makedirs(serverdir)
|
||||||
|
|||||||
Reference in New Issue
Block a user