From 96171013d61c9b6542651291877cddbdc05b8eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Thu, 28 Nov 2024 15:10:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8E=92=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_plan/models/custom_plan.py | 73 +++++++++++++++-------------------- 1 file changed, 31 insertions(+), 42 deletions(-) diff --git a/sf_plan/models/custom_plan.py b/sf_plan/models/custom_plan.py index e7785ad4..7fcec54e 100644 --- a/sf_plan/models/custom_plan.py +++ b/sf_plan/models/custom_plan.py @@ -232,41 +232,37 @@ class sf_production_plan(models.Model): raise ValidationError("未选择生产线") else: # 自动化产线加工 - if record.production_id.production_type == '自动化产线加工': - if record.production_id.workorder_ids: - last_cnc_start = record.date_planned_start if record.date_planned_start else datetime.now() - for item in record.production_id.workorder_ids: - if item.name == 'CNC加工': - # 将同一个面的所有工单筛选出来 - workorder_list = record.production_id.workorder_ids.filtered(lambda x: x.processing_panel == item.processing_panel) - routing_workcenter = record.env['mrp.routing.workcenter'].sudo().search( - [('name', '=', 'CNC加工')], limit=1) - # 设置一个小的开始时间 - item.date_planned_start = datetime.now() - timedelta(days=100) - item.date_planned_finished = last_cnc_start + timedelta( - minutes=routing_workcenter.time_cycle) - item.date_planned_start = last_cnc_start - record.sudo().production_id.plan_start_processing_time = item.date_planned_start - item.duration_expected = routing_workcenter.time_cycle - pre_duration , next_duration = record.calculate_plan_time(item, workorder_list) - record.date_planned_finished = item.date_planned_finished - # 计算下一个cnc工单的开始时间 - last_cnc_start = workorder_list[-1].date_planned_finished + timedelta(minutes=pre_duration) - # 没有工单也能排程 - else: - # 人工线下加工只排第一张工单 - if record.production_id.workorder_ids: - item = record.production_id.workorder_ids[0] - last_wo_start = record.date_planned_start if record.date_planned_start else datetime.now() - routing_workcenter = record.env['mrp.routing.workcenter'].sudo().search( - [('name', '=', item.routing_type)], limit=1) - item.date_planned_start = datetime.now() - timedelta(days=100) - item.date_planned_finished = last_wo_start + timedelta( + if record.production_id.workorder_ids: + # 自动化产线加工 + if record.production_id.production_type == '自动化产线加工': + # 找到第一张CNC加工工单 + first_cnc_workorder = record.production_id.workorder_ids.filtered(lambda x: x.name == 'CNC加工')[0] + date_start = record.date_planned_start if record.date_planned_start else datetime.now() + routing_workcenter = first_cnc_workorder.technology_design_id.route_id + # 设置一个小的开始时间 + first_cnc_workorder.date_planned_start = datetime.now() - timedelta(days=100) + first_cnc_workorder.date_planned_finished = date_start + timedelta( minutes=routing_workcenter.time_cycle) - item.date_planned_start = last_wo_start + first_cnc_workorder.date_planned_start = date_start + record.sudo().production_id.plan_start_processing_time = first_cnc_workorder.date_planned_start + first_cnc_workorder.duration_expected = routing_workcenter.time_cycle + record.calculate_plan_time(first_cnc_workorder, record.production_id.workorder_ids) + # 找到最后一张CNC加工工单 + last_cnc_workorder = record.production_id.workorder_ids.filtered(lambda x: x.name == 'CNC加工')[-1] + record.date_planned_finished = last_cnc_workorder.date_planned_finished + else: + # 人工线下加工只排第一张工单 + item = record.production_id.workorder_ids[0] + wo_start = record.date_planned_start if record.date_planned_start else datetime.now() + item.date_planned_start = datetime.now() - timedelta(days=100) + item.date_planned_finished = wo_start + timedelta( + minutes=routing_workcenter.time_cycle) + item.date_planned_start = wo_start record.sudo().production_id.plan_start_processing_time = item.date_planned_start item.duration_expected = routing_workcenter.time_cycle - record.calculate_plan_time(item, item) + record.calculate_plan_time(item, record.production_id.workorder_ids) + last_cnc_workorder = record.production_id.workorder_ids[-1] + record.date_planned_finished = last_cnc_workorder.date_planned_finished record.state = 'done' # record.production_id.schedule_state = '已排' record.sudo().production_id.schedule_state = '已排' @@ -328,38 +324,31 @@ class sf_production_plan(models.Model): if workorder.id == item.id: item_position = index break - routing_workcenters = self.env['mrp.routing.workcenter'].sudo().search([]) - # 记录所有前序工序时长 - previous_workorder_duration = 0 for i in range(item_position, -1, -1): if i < 1: break current_workorder = workorder_list[i] next_workorder = workorder_list[i - 1] - routing_workcenter = routing_workcenters.filtered(lambda x: x.name == next_workorder.name)[0] + routing_workcenter = next_workorder.technology_design_id.route_id # 设置一个小的开始时间 next_workorder.date_planned_start = datetime.now() - timedelta(days=100) next_workorder.date_planned_finished = current_workorder.date_planned_start next_workorder.date_planned_start = next_workorder.date_planned_finished - timedelta( minutes=routing_workcenter.time_cycle) next_workorder.duration_expected = routing_workcenter.time_cycle - previous_workorder_duration += routing_workcenter.time_cycle - # 记录所有后续工序时长 - next_workorder_duration = 0 + for i in range(item_position, len(workorder_list) - 1): if i > len(workorder_list) - 1: break current_workorder = workorder_list[i] next_workorder = workorder_list[i + 1] - routing_workcenter = routing_workcenters.filtered(lambda x: x.name == next_workorder.name)[0] + routing_workcenter = next_workorder.technology_design_id.route_id # 设置一个小的开始时间 next_workorder.date_planned_start = datetime.now() - timedelta(days=100) next_workorder.date_planned_finished = current_workorder.date_planned_finished + timedelta( minutes=routing_workcenter.time_cycle) next_workorder.date_planned_start = current_workorder.date_planned_finished next_workorder.duration_expected = routing_workcenter.time_cycle - next_workorder_duration += routing_workcenter.time_cycle - return previous_workorder_duration, next_workorder_duration def calculate_plan_time_after(self, item, workorder_id_list): """