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

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

@@ -157,7 +157,8 @@ class Manufacturing_Connect(http.Controller):
if workorder.state != 'ready':
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '工单未就绪'}
return json.JSONEncoder().encode(res)
work_equipment_id = request.env['maintenance.equipment'].sudo().search([('name', '=', equipment_id)], limit=1)
work_equipment_id = request.env['maintenance.equipment'].sudo().search([('name', '=', equipment_id)],
limit=1)
if not work_equipment_id:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '没有找到该加工设备'}
return json.JSONEncoder().encode(res)
@@ -212,8 +213,18 @@ class Manufacturing_Connect(http.Controller):
ret = json.loads(datas)
production_id = ret['BillId']
routing_type = ret['CraftId']
request.env['mrp.workorder'].sudo().search(
workorder = request.env['mrp.workorder'].sudo().search(
[('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'])
if download_state is not False:
request.env['mrp.workorder'].sudo().get_detection_file(workorder, ret['ReportPaht'])
else:
res = {'Succeed': False, 'ErrorCode': 204, 'Error': '检测报告文件从FTP拉取失败'}
else:
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '未传ReportPaht字段'}
except Exception as e:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
logging.info('PartQualityInspect error:%s' % e)
@@ -338,8 +349,10 @@ class Manufacturing_Connect(http.Controller):
[('feeder_station_destination', '=', ret['DeviceId'])])
if workpiece_delivery:
for wd in workpiece_delivery:
if wd.production_id.production_line_state == '待上产线':
logging.info('wd.production_id:%s' % workpiece_delivery.production_id.id)
logging.info('wd.workorder_id:%s' % wd.workorder_id.name)
if wd.workorder_id.state == 'done' and wd.production_id.production_line_state == '待上产线':
logging.info('wd.production_id:%s' % wd.production_id.name)
logging.info('wd.production_line_state:%s' % wd.production_id.production_line_state)
wd.production_id.write({'production_line_state': '已上产线'})
else:
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '该DeviceId没有对应的工件配送数据'}
@@ -370,8 +383,10 @@ class Manufacturing_Connect(http.Controller):
[('feeder_station_destination', '=', ret['DeviceId'])])
if workpiece_delivery:
for wd in workpiece_delivery:
if wd.production_id.production_line_state == '已上产线':
logging.info('wd.production_id:%s' % workpiece_delivery.production_id.id)
logging.info('wd.workorder_id:%s' % wd.workorder_id.name)
if wd.workorder_id.state == 'done' and wd.production_id.production_line_state == '已上产线':
logging.info('wd.production_id:%s' % wd.production_id.name)
logging.info('wd.production_line_state:%s' % wd.production_id.production_line_state)
wd.production_id.write({'production_line_state': '已下产线'})
else:
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '该DeviceId没有对应的工件配送数据'}

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

View File

@@ -414,7 +414,7 @@
<field name="production_id" invisible="1"/>
<field name="workpiece_code"/>
<field name="feeder_station_start" force_save="1"/>
<field name="feeder_station_destination"/>
<field name="feeder_station_destination" force_save="1"/>
<field name="production_line_id"/>
<field name="task_delivery_time" readonly="1"/>
<field name="task_completion_time" readonly="1"/>
@@ -429,9 +429,9 @@
<field name="results" invisible="1"/>
<page string="后置三元检测" attrs='{"invisible": [("routing_type","!=","CNC加工")]}'>
<group>
<field name="detection_report_path" attrs='{"invisible":[("results","!=",False)]}'/>
<field name="test_results" widget="selection" attrs='{"invisible":[("results","!=",False)]}'/>
<field name="results" readonly="1" attrs='{"invisible":[("results","!=","合格")]}'/>
<field name="detection_report" attrs='{"invisible":[("results","!=",False)]}' widget="pdf_viewer"/>
</group>
<div class="col-12 col-lg-6 o_setting_box">
<button type="object" class="oe_highlight" name="recreateManufacturingOrWorkerOrder"

View File

@@ -29,6 +29,7 @@ class FtpController():
logging.info("进入FTP目录 ")
self.ftp.cwd(target_dir) # 切换工作路径
logging.info('FTP目录:%s' % target_dir)
self.ftp.mkd('detection')
remotenames = self.ftp.nlst()
logging.info('FTP目录文件:%s' % remotenames)
for file in remotenames: