Accept Merge Request #766: (feature/修改机床参数bug -> develop)

Merge Request: 处理CNC文件下发失败的bug

Created By: @龚启豪
Reviewed By: @马广威
Approved By: @马广威 
Accepted By: @龚启豪
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/766
This commit is contained in:
龚启豪
2024-01-10 15:50:57 +08:00
committed by Coding
4 changed files with 22 additions and 14 deletions

View File

@@ -195,15 +195,15 @@ class SfMaintenanceEquipment(models.Model):
machine_tool_id = fields.Many2one('sf.machine_tool', '机床')
sf_maintenance_logs_ids = fields.One2many('sf.maintenance.logs', 'maintenance_equipment_id', '设备故障日志')
def name_get(self):
result = []
for parameter in self:
if parameter.code:
name = parameter.name + '-' + parameter.code
else:
name = parameter.name
result.append((parameter.id, name))
return result
# def name_get(self):
# result = []
# for parameter in self:
# if parameter.code:
# name = parameter.name + '-' + parameter.code
# else:
# name = parameter.name
# result.append((parameter.id, name))
# return result
@api.model
def create(self, vals):

View File

@@ -608,7 +608,7 @@ class CNCprocessing(models.Model):
estimated_processing_time = fields.Char('预计加工时间')
remark = fields.Text('备注')
workorder_id = fields.Many2one('mrp.workorder', string="工单")
workorder_id = fields.Many2one('mrp.production', string="制造")
production_id = fields.Many2one('mrp.production', string="制造")
button_state = fields.Boolean(string='是否已经下发')
# mrs下发编程单创建CNC加工
@@ -618,6 +618,8 @@ class CNCprocessing(models.Model):
workorder = self.env['mrp.workorder'].search([('production_id.name', '=', ret['production_order_no']),
('processing_panel', '=', obj['processing_panel']),
('routing_type', '=', 'CNC加工')])
logging.info('workorder:%s' % workorder)
logging.info('obj:%s' % obj)
cnc_processing = self.env['sf.cnc.processing'].create({
'workorder_id': workorder.id,
'sequence_number': obj['sequence_number'],
@@ -633,7 +635,7 @@ class CNCprocessing(models.Model):
'estimated_processing_time': obj['estimated_processing_time'],
'remark': obj['remark']
})
self.get_cnc_processing_file(ret['folder_name'], cnc_processing, workorder.processing_panel)
cnc_processing.get_cnc_processing_file(ret['folder_name'], cnc_processing, workorder.processing_panel)
# cnc_workorder.state = 'done'
cnc_workorder.work_state = '已编程'
cnc_workorder.programming_state = '已编程'
@@ -645,7 +647,7 @@ class CNCprocessing(models.Model):
logging.info('folder_name:%s' % folder_name)
serverdir = os.path.join('/tmp', folder_name, 'return', processing_panel)
logging.info('serverdir:%s' % serverdir)
for root, files in os.walk(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":
@@ -680,6 +682,7 @@ class CNCprocessing(models.Model):
ftp = FtpController(str(ftp_resconfig['ftp_host']), int(ftp_resconfig['ftp_port']), ftp_resconfig['ftp_user'],
ftp_resconfig['ftp_password'])
download_state = ftp.download_file_tree(remotepath, serverdir)
logging.info('download_state:%s' % download_state)
return download_state
# 将nc文件存到attach的datas里

View File

@@ -22,22 +22,26 @@ class Sf_Mrs_Connect(http.Controller):
datas = request.httprequest.data
ret = json.loads(datas)
ret = json.loads(ret['result'])
logging.info('下发编程单:%s' % ret)
# 查询状态为进行中且类型为获取CNC加工程序的工单
cnc_production = request.env['mrp.production'].with_user(
request.env.ref("base.user_admin")).search([('name', '=', ret['production_order_no'])])
logging.info('制造订单号:%s' % cnc_production.name)
if cnc_production:
if ret['glb_file']:
cnc_production.glb_file = base64.b64encode(ret['glb_file'])
# 拉取所有加工面的程序文件
# i = 1
for r in ret['processing_panel']:
download_state = request.env['sf.cnc.processing'].with_user(
request.env.ref("base.user_admin")).download_file_tmp(
ret['folder_name'], r)
if not download_state:
if download_state == 0:
res['status'] = -2
res['message'] = '制造订单号为%s的CNC程序文件从FTP拉取失败' % (cnc_production.name)
return json.JSONEncoder().encode(res)
logging.info('创建cnc工单')
request.env['sf.cnc.processing'].with_user(
request.env.ref("base.user_admin")).cnc_processing_create(cnc_production, ret)
return json.JSONEncoder().encode(res)

View File

@@ -35,8 +35,9 @@ class FtpController():
server = os.path.join(serverdir, file)
if file.find(".") != -1:
self.download_file(server, file)
return 1
except Exception:
return False
return 0
# 下载指定目录下的指定文件
def download_file(self, serverfile, remotefile):