Accept Merge Request #926: (feature/优化下发编程单的同时拉取CMM程序 -> develop)

Merge Request: 优化下发编程单的同时拉取CMM程序

Created By: @杨金灵
Reviewed By: @马广威
Approved By: @马广威 
Accepted By: @杨金灵
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/926?initial=true
This commit is contained in:
杨金灵
2024-03-29 16:55:31 +08:00
committed by Coding
3 changed files with 97 additions and 10 deletions

View File

@@ -736,7 +736,7 @@ class CNCprocessing(models.Model):
# cnc_workorder.time_ids.date_end = datetime.now()
# cnc_workorder.button_finish()
# 根据程序名和加工面匹配到ftp里对应的Nc程序名
# 根据程序名和加工面匹配到ftp里对应的Nc程序名,可优化为根据cnc_processing.program_path进行匹配
def get_cnc_processing_file(self, serverdir, cnc_processing, program_path):
logging.info('serverdir:%s' % serverdir)
for root, dirs, files in os.walk(serverdir):
@@ -778,7 +778,7 @@ class CNCprocessing(models.Model):
# 将nc文件存到attach的datas里
def write_file(self, nc_file_path, cnc):
nc_file_name = nc_file_path.split('/')
logging.info('nc_file_name:%s' % nc_file_name[-1])
logging.info('file_name:%s' % nc_file_name[-1])
if os.path.exists(nc_file_path):
with open(nc_file_path, 'rb') as file:
data_bytes = file.read()
@@ -910,7 +910,8 @@ class WorkPieceDelivery(models.Model):
# 配送至avg小车
def _delivery_avg(self):
res = {'reqCode': urllib.parse.quote(self.production_id.name), 'reqTime': '', 'clientCode': '', 'tokenCode': '',
'taskTyp': 'F01', 'ctnrTyp': '', 'ctnrCode': '', 'wbCode': '006848AB006774', 'positionCodePath': [], 'podCode': '',
'taskTyp': 'F01', 'ctnrTyp': '', 'ctnrCode': '', 'wbCode': '006848AB006774', 'positionCodePath': [],
'podCode': '',
'podDir': '', 'materialLot': '', 'priority': '', 'taskCode': '', 'agvCode': '', 'materialLot': '',
'data': ''}
config = self.env['res.config.settings'].get_values()
@@ -951,7 +952,77 @@ class CMMprogram(models.Model):
_name = 'sf.cmm.program'
_description = "CMM程序"
program_path = fields.Char('程序文件路径')
post_processing_name = fields.Char('后处理名称')
program_date = fields.Datetime('程序日期')
cmm_id = fields.Many2one('ir.attachment')
sequence_number = fields.Integer('序号')
program_name = fields.Char('程序')
cutting_tool_name = fields.Char('刀具名称')
cutting_tool_no = fields.Char('刀号')
processing_type = fields.Char('加工类型')
margin_x_y = fields.Char('余量_X/Y')
margin_z = fields.Char('余量_Z')
depth_of_processing_z = fields.Char('加工深度(Z)')
cutting_tool_extension_length = fields.Char('刀具伸出长度')
cutting_tool_handle_type = fields.Char('刀柄型号')
estimated_processing_time = fields.Char('预计加工时间')
remark = fields.Text('备注')
workorder_id = fields.Many2one('mrp.workorder', string="工单")
production_id = fields.Many2one('mrp.production', string="制造订单")
program_path = fields.Char('程序文件路径')
def cmm_program_create(self, ret, program_path, program_path_tmp):
for obj in ret['programming_list']:
workorder = self.env['mrp.workorder'].search([('production_id.name', '=', ret['production_order_no']),
('processing_panel', '=', obj['processing_panel']),
('routing_type', '=', 'CNC加工')])
if obj['program_name'] in program_path:
logging.info('obj:%s' % obj['program_name'])
cmm_program = self.sudo().create({
'workorder_id': workorder.id,
'sequence_number': obj['sequence_number'],
'program_name': obj['program_name'],
'cutting_tool_name': obj['cutting_tool_name'],
'cutting_tool_no': obj['cutting_tool_no'],
'processing_type': obj['processing_type'],
'margin_x_y': obj['margin_x_y'],
'margin_z': obj['margin_z'],
'depth_of_processing_z': obj['depth_of_processing_z'],
'cutting_tool_extension_length': obj['cutting_tool_extension_length'],
'cutting_tool_handle_type': obj['cutting_tool_handle_type'],
'estimated_processing_time': obj['estimated_processing_time'],
'remark': obj['remark'],
'program_path': program_path.replace('/tmp', '')
})
cmm_program.get_cmm_program_file(program_path_tmp, cmm_program, program_path)
# 根据程序名和加工面匹配到ftp里对应的cmm程序名
def get_cmm_program_file(self, serverdir, cmm_program, program_path):
logging.info('cmm-serverdir:%s' % serverdir)
for root, dirs, files in os.walk(serverdir):
for f in files:
if f in program_path:
cmm_program_file_path = os.path.join(serverdir, root, f)
self.write_file_cmm(cmm_program_file_path, cmm_program)
# 创建附件(nc文件)
def attachment_create(self, name, data):
attachment = self.env['ir.attachment'].create({
'datas': base64.b64encode(data),
'type': 'binary',
'public': True,
'description': '程序文件',
'name': name
})
return attachment
# 将cmm文件存到attach的datas里
def write_file_cmm(self, cmm_file_path, cnc):
cmm_file_name = cmm_file_path.split('/')
logging.info('cmm_file_name:%s' % cmm_file_name[-1])
if os.path.exists(cmm_file_path):
with open(cmm_file_path, 'rb') as file:
data_bytes = file.read()
attachment = self.attachment_create(cnc.program_name + cmm_file_name[-1], data_bytes)
cnc.write({'cmm_id': attachment.id})
file.close()
else:
return False

View File

@@ -476,9 +476,19 @@
<page string="CMM程序" attrs='{"invisible": [("routing_type","!=","CNC加工")]}'>
<field name="cmm_ids" widget="one2many" string="CMM程序">
<tree>
<field name="program_path"/>
<field name="program_date"/>
<field name="post_processing_name"/>
<field name="sequence_number"/>
<field name="program_name"/>
<field name="cmm_id" string="文件"/>
<field name="cutting_tool_name"/>
<field name="cutting_tool_no"/>
<field name="processing_type"/>
<field name="margin_x_y"/>
<field name="margin_z"/>
<field name="depth_of_processing_z"/>
<field name="cutting_tool_extension_length"/>
<field name="cutting_tool_handle_type"/>
<field name="estimated_processing_time"/>
<field name="remark"/>
</tree>
</field>
</page>

View File

@@ -44,12 +44,18 @@ class Sf_Mrs_Connect(http.Controller):
return json.JSONEncoder().encode(res)
logging.info('创建cnc工单')
program_path_tmp = os.path.join('/tmp', ret['folder_name'], 'return', r)
# program_path_tmp = "C://Users//43484//Desktop//机企猫工作文档//其他//model_analysis"
files = os.listdir(program_path_tmp)
for f in files:
program_path = os.path.join(program_path_tmp, f)
logging.info('cnc程序路径 :%s' % program_path)
if f.endswith(".doc"):
# 插入cmm程序数据
request.env['sf.cmm.program'].with_user(
request.env.ref("base.user_admin")).cmm_program_create(ret, program_path, program_path_tmp)
request.env['sf.cnc.processing'].with_user(
request.env.ref("base.user_admin")).cnc_processing_create(cnc_production, ret, program_path,program_path_tmp)
request.env.ref("base.user_admin")).cnc_processing_create(cnc_production, ret, program_path,
program_path_tmp)
return json.JSONEncoder().encode(res)
else:
res = {'status': 0, 'message': '该制造订单暂未开始'}