修复返工bug

This commit is contained in:
jinling.yang
2024-07-19 17:25:51 +08:00
parent 9d3c4f8163
commit 8a0c968b10
6 changed files with 134 additions and 60 deletions

View File

@@ -44,6 +44,25 @@ class ReworkWizard(models.TransientModel):
self.workorder_id.button_finish()
else:
if self.production_id.workorder_ids:
handle_result = self.production_id.detection_result_ids.filtered(
lambda dr: dr.handle_result == '待处理')
if handle_result:
processing_panels_to_handle = set(handle_item.processing_panel for handle_item in handle_result)
processing_panels_choice = set(dr_panel.name for dr_panel in self.processing_panel_id)
# 使用集合的差集操作找出那些待处理结果中有但实际可用加工面中没有的加工面
processing_panels_missing = processing_panels_to_handle - processing_panels_choice
# 存在不一致的加工面
if processing_panels_missing:
processing_panels_str = ','.join(processing_panels_missing)
raise UserError('您还有待处理的检测结果中为%s的加工面未选择' % processing_panels_str)
# processing_panels = set()
# for handle_item in handle_result:
# for dr_panel in self.processing_panel_id:
# if dr_panel.name == handle_item.processing_panel:
# processing_panels.add(dr_panel.name)
# if len(processing_panels) != len(handle_result):
# processing_panels_str = ','.join(processing_panels)
# return UserError(f'您还有待处理的检测结果中为{processing_panels_str}的加工面未选择')
for panel in self.processing_panel_id:
panel_workorder = self.production_id.workorder_ids.filtered(
lambda ap: ap.processing_panel == panel.name and ap.state != 'rework')
@@ -60,19 +79,74 @@ class ReworkWizard(models.TransientModel):
self.env['mrp.workorder'].json_workorder_str(panel.name,
self.production_id, route, False))
if workorders_values:
self.production_id.write(
{'workorder_ids': workorders_values, 'programming_state': '编程中', 'work_state': '编程中',
'reprogramming_num': self.production_id.reprogramming_num + 1})
self.production_id.write({'workorder_ids': workorders_values, 'is_rework': True})
self.production_id._reset_work_order_sequence()
self.production_id.detection_result_ids.filtered(
lambda ap1: ap1.processing_panel == panel.name and ap1.handle_result == '待处理').write(
{'handle_result': '已处理'})
if self.is_reprogramming is False:
self.production_id.get_new_program(panel)
if self.reprogramming_num >= 1:
self.production_id.get_new_program(panel)
else:
ret = {'programming_list': []}
cnc_rework = self.production_id.workorder_ids.filtered(
lambda crw: crw.processing_panel == panel.name and crw.state in (
'rework') and crw.routing_type == 'CNC加工')
if cnc_rework.cnc_ids:
for item_line in cnc_rework.cnc_ids:
vals = {
'processing_panel': item_line.processing_panel,
'sequence_number': item_line.sequence_number,
'program_name': item_line.program_name,
'cutting_tool_name': item_line.cutting_tool_name,
'cutting_tool_no': item_line.cutting_tool_no,
'processing_type': item_line.processing_type,
'margin_x_y': item_line.margin_x_y,
'margin_z': item_line.margin_z,
'depth_of_processing_z': item_line.depth_of_processing_z,
'cutting_tool_extension_length': item_line.cutting_tool_extension_length,
'estimated_processing_time': item_line.estimated_processing_time,
'cutting_tool_handle_type': item_line.cutting_tool_handle_type,
'ftp_path': item_line.ftp_path,
'program_create_date': datetime.strftime(item_line.program_create_date,
'%Y-%m-%d %H:%M:%S'),
'remark': item_line.remark
}
ret['programming_list'].append(vals)
for cmm_line in cnc_rework.cmm_ids:
vals = {
'sequence_number': cmm_line.sequence_number,
'program_name': cmm_line.program_name,
'ftp_path': cmm_line.ftp_path,
'program_create_date': datetime.strftime(cmm_line.program_create_date,
'%Y-%m-%d %H:%M:%S')
}
ret['programming_list'].append(vals)
new_cnc_workorder = self.production_id.workorder_ids.filtered(
lambda ap1: ap1.processing_panel == panel.name and ap1.state not in (
'rework', 'done') and ap1.routing_type == 'CNC加工')
if not new_cnc_workorder.cnc_ids:
new_cnc_workorder.write({
'cnc_ids': new_cnc_workorder.cnc_ids.sudo()._json_cnc_processing(panel.name,
ret),
'cmm_ids': new_cnc_workorder.cmm_ids.sudo()._json_cmm_program(panel.name, ret),
'cnc_worksheet': new_cnc_workorder.cnc_worksheet})
new_pre_workorder = self.production_id.workorder_ids.filtered(lambda
p: p.routing_type == '装夹预调' and p.processing_panel == panel.name and p.state not in (
'rework', 'done'))
if new_pre_workorder:
pre_rework = self.production_id.workorder_ids.filtered(
lambda pr: pr.processing_panel == panel.name and pr.state in (
'rework') and crw.routing_type == '装夹预调')
new_pre_workorder.write(
{'processing_drawing': pre_rework.processing_drawing})
self.production_id.write({'state': 'progress'})
if self.is_reprogramming is True:
self.production_id.update_programming_state()
self.production_id.write(
{'programming_state': '编程中', 'work_state': '编程中'})
if self.production_id.state == 'progress':
self.production_id.write({'programming_state': '已编程'})
self.production_id.write({'programming_state': '已编程', 'work_state': '编程中'})
@api.onchange('production_id')
def onchange_processing_panel_id(self):