diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index b0e31287..b5566f82 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -1151,21 +1151,13 @@ class CNCprocessing(models.Model): logging.info('splitext(f):%s' % os.path.splitext(f)[1]) if os.path.splitext(f)[1] == ".pdf": full_path = os.path.join(serverdir, root, f) - logging.info('full_path:%s' % full_path) - logging.info('routing_type:%s' % cnc_processing.workorder_id.routing_type) - logging.info('cnc_worksheet:%s' % cnc_processing.workorder_id.cnc_worksheet) - # with open(full_path, 'rb') as pdf_file: - # file_content = pdf_file.read() - # cnc_processing.workorder_id.cnc_worksheet = base64.b64encode(file_content) - if not cnc_processing.workorder_id.cnc_worksheet: - logging.info('full_path111555:%s' % full_path) - cnc_processing.workorder_id.cnc_worksheet = base64.b64encode( - open(full_path, 'rb').read()) - else: - if f in program_path: - # if cnc_processing.program_name == f.split('.')[0]: - cnc_file_path = os.path.join(serverdir, root, f) - self.write_file(cnc_file_path, cnc_processing) + cnc_processing.workorder_id.cnc_worksheet = base64.b64encode( + open(full_path, 'rb').read()) + else: + if f in program_path: + # if cnc_processing.program_name == f.split('.')[0]: + cnc_file_path = os.path.join(serverdir, root, f) + self.write_file(cnc_file_path, cnc_processing) # 创建附件(nc文件) def attachment_create(self, name, data): diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py index 7498ec75..78a0c05a 100644 --- a/sf_mrs_connect/controllers/controllers.py +++ b/sf_mrs_connect/controllers/controllers.py @@ -24,12 +24,22 @@ class Sf_Mrs_Connect(http.Controller): ret = json.loads(datas) ret = json.loads(ret['result']) logging.info('下发编程单:%s' % ret) + is_delete_file = False # 查询状态为进行中且类型为获取CNC加工程序的工单 cnc_production = request.env['mrp.production'].with_user( request.env.ref("base.user_admin")).search([('name', '=', ret['production_order_no'].split(',')[0])]) cnc_program = request.env['mrp.production'].with_user( request.env.ref("base.user_admin")).search( [('programming_no', '=', cnc_production.programming_no), ('id', '!=', cnc_production.id)]) + if cnc_production.workorder_ids.filtered(lambda a: a.routing_type == 'CNC加工').cnc_ids: + is_delete_file = True + cnc_production.workorder_ids.filtered( + lambda a1: a1.routing_type == 'CNC加工').cnc_ids.sudo().unlink() + request.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan(cnc_production) + if cnc_program.workorder_ids.filtered(lambda c: c.routing_type == 'CNC加工').cnc_ids: + cnc_program.workorder_ids.filtered( + lambda c1: c1.routing_type == 'CNC加工').cnc_ids.sudo().unlink() + request.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan(cnc_program) # cnc_program = request.env['mrp.production'].with_user( # request.env.ref("base.user_admin")).search([('programming_no', '=', cnc_production.programming_no)]) logging.info('制造订单号:%s' % cnc_production.name) @@ -37,6 +47,13 @@ class Sf_Mrs_Connect(http.Controller): # if ret['glb_file']: # cnc_production.glb_file = base64.b64encode(ret['glb_file']) # 拉取所有加工面的程序文件 + if is_delete_file is True: + program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', 'R') + files_r = os.listdir(program_path_tmp_r) + if files_r: + for file_name in files_r: + file_path = os.path.join(program_path_tmp_r, file_name) + os.remove(file_path) for r in ret['processing_panel']: download_state = request.env['sf.cnc.processing'].with_user( request.env.ref("base.user_admin")).download_file_tmp( @@ -64,15 +81,17 @@ class Sf_Mrs_Connect(http.Controller): if cnc_processing: cnc_processing_arr.append(cnc_processing._json_cnc_processing(cnc_processing)) if (cnc_program and cnc_processing_arr) or (not cnc_program and cnc_processing_arr): - logging.info('cnc_processing_arr:%s' % cnc_processing_arr) + cnc_production.workorder_ids.filtered(lambda g: g.routing_type == '装夹预调').write( + {'processing_drawing': cnc_production.workorder_ids.filtered( + lambda g1: g1.routing_type == 'CNC加工').cnc_worksheet}) if cnc_program and cnc_processing_arr: cnc_program.write({'programming_state': '已编程', 'work_state': '已编程'}) - cnc_program.workorder_ids.filtered(lambda b1: b1.routing_type == '装夹预调').write( + cnc_program.workorder_ids.filtered(lambda d: d.routing_type == '装夹预调').write( {'processing_drawing': cnc_production.workorder_ids.filtered( - lambda b1: b1.routing_type == 'CNC加工').cnc_worksheet}) + lambda d1: d1.routing_type == 'CNC加工').cnc_worksheet}) cnc_program.workorder_ids.filtered(lambda b: b.routing_type == 'CNC加工').write( {'cnc_ids': cnc_processing_arr, 'cnc_worksheet': cnc_production.workorder_ids.filtered( - lambda b: b.routing_type == 'CNC加工').cnc_worksheet}) + lambda b1: b1.routing_type == 'CNC加工').cnc_worksheet}) cnc_program |= cnc_production if not cnc_program and cnc_processing_arr: cnc_program = cnc_production diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py index 122989d9..5bfc087b 100644 --- a/sf_tool_management/models/base.py +++ b/sf_tool_management/models/base.py @@ -348,6 +348,18 @@ class CAMWorkOrderProgramKnifePlan(models.Model): else: logging.info('功能刀具【%s】满足CNC用刀需求!!!' % cnc_processing.cutting_tool_name) + def unlink_cam_plan(self, production): + for item in production: + cam_plan_ids = self.env['sf.cam.work.order.program.knife.plan'].search([('name', '=', item.name)]) + for cam_plan_id in cam_plan_ids: + assembly_id = cam_plan_id.sf_functional_tool_assembly_id + if assembly_id.assemble_status in ('0', '待组装') and not assembly_id.start_preset_bool: + logging.info('%s删除成功!!!' % assembly_id) + assembly_id.sudo().unlink() + logging.info('unlink_cam_plan成功!!!') + cam_plan_ids.sudo().unlink() + + class FunctionalToolAssembly(models.Model): _name = 'sf.functional.tool.assembly'