diff --git a/sf_manufacturing/controllers/controllers.py b/sf_manufacturing/controllers/controllers.py
index 9d23a1b9..2c706063 100644
--- a/sf_manufacturing/controllers/controllers.py
+++ b/sf_manufacturing/controllers/controllers.py
@@ -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没有对应的工件配送数据'}
diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py
index 39333a15..931da029 100644
--- a/sf_manufacturing/models/mrp_workorder.py
+++ b/sf_manufacturing/models/mrp_workorder.py
@@ -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):
diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml
index cf4fa679..231b40eb 100644
--- a/sf_manufacturing/views/mrp_workorder_view.xml
+++ b/sf_manufacturing/views/mrp_workorder_view.xml
@@ -414,7 +414,7 @@
-
+
@@ -429,9 +429,9 @@
-
+