修复更新程序

This commit is contained in:
jinling.yang
2024-07-24 17:10:35 +08:00
parent befe0c2b00
commit 3ed503391e

View File

@@ -870,46 +870,46 @@ class MrpProduction(models.Model):
[('programming_no', '=', self.programming_no), ('state', 'not in', ('cancel', 'done'))]) [('programming_no', '=', self.programming_no), ('state', 'not in', ('cancel', 'done'))])
logging.info('get_new_program productions:%s' % productions) logging.info('get_new_program productions:%s' % productions)
if productions: if productions:
workorder_ids = set()
for production in productions: for production in productions:
for workorder in production.workorder_ids: panel_workorder = production.workorder_ids.filtered(lambda
if workorder.processing_panel == processing_panel and workorder.routing_type == 'CNC加工' and workorder.state not in ( pw: pw.processing_panel == processing_panel and pw.routing_type == 'CNC加工' and pw.state not in (
'rework', 'done'): 'rework', 'done'))
workorder_ids.add(workorder.id) logging.info('get_new_program panel_workorder:%s' % panel_workorder)
panel_workorder = self.env['mrp.workorder'].search([('id', 'in', list(workorder_ids))]) if panel_workorder:
logging.info('get_new_program panel_workorder:%s' % panel_workorder)
if panel_workorder:
if panel_workorder.cnc_ids:
logging.info('get_new_program 1') logging.info('get_new_program 1')
panel_workorder.cmm_ids.sudo().unlink() if panel_workorder.cmm_ids:
panel_workorder.cnc_ids.sudo().unlink() panel_workorder.cmm_ids.sudo().unlink()
logging.info('get_new_program 2') if panel_workorder.cnc_ids:
self.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan( panel_workorder.cnc_ids.sudo().unlink()
productions) logging.info('get_new_program 2')
logging.info('get_new_program 3') self.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan(
# program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', production)
# processing_panel) logging.info('get_new_program 3')
logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel) # program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test',
files_panel = os.listdir(program_path_tmp_panel) # processing_panel)
if files_panel: logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel)
for file in files_panel: files_panel = os.listdir(program_path_tmp_panel)
file_extension = os.path.splitext(file)[1] if files_panel:
if file_extension.lower() == '.pdf': for file in files_panel:
panel_file_path = os.path.join(program_path_tmp_panel, file) file_extension = os.path.splitext(file)[1]
logging.info('panel_file_path:%s' % panel_file_path) if file_extension.lower() == '.pdf':
logging.info('get_new_program 4') panel_file_path = os.path.join(program_path_tmp_panel, file)
panel_workorder.write( logging.info('panel_file_path:%s' % panel_file_path)
{'cnc_ids': panel_workorder.cnc_ids.sudo()._json_cnc_processing(processing_panel, result), logging.info('get_new_program 4')
'cmm_ids': panel_workorder.cmm_ids.sudo()._json_cmm_program(processing_panel, result), panel_workorder.write(
'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())}) {'cnc_ids': panel_workorder.cnc_ids.sudo()._json_cnc_processing(processing_panel,
logging.info('get_new_program 5') result),
pre_workorder = productions.workorder_ids.filtered(lambda 'cmm_ids': panel_workorder.cmm_ids.sudo()._json_cmm_program(processing_panel, result),
ap: ap.routing_type == '装夹预调' and ap.processing_panel == processing_panel and ap.state != 'rework') 'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())})
logging.info('get_new_program 6') logging.info('get_new_program 5')
if pre_workorder: pre_workorder = production.workorder_ids.filtered(lambda
pre_workorder.write( ap: ap.routing_type == '装夹预调' and ap.processing_panel == processing_panel and ap.state not in (
{'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())}) 'rework', 'done'))
logging.info('get_new_program 7') logging.info('get_new_program 6')
if pre_workorder:
pre_workorder.write(
{'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())})
logging.info('get_new_program 7')
else: else:
raise UserError(result['message']) raise UserError(result['message'])
except Exception as e: except Exception as e: