From d4ba58b55ab397b4c66534d6a617af197efb1401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Thu, 28 Nov 2024 10:17:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8E=92=E7=A8=8B=E5=8D=95?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_workorder.py | 3 +- sf_plan/models/custom_plan.py | 56 +++++++++++++++--------- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 4e94044a..157717bc 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -1378,7 +1378,8 @@ class ResMrpWorkOrder(models.Model): # workorder.rfid_code_old = rfid_code # workorder.rfid_code = False logging.info('workorder.rfid_code:%s' % workorder.rfid_code) - if is_production_id is True and record.routing_type in ['解除装夹', '表面工艺', '切割']: + # if is_production_id is True and record.routing_type in ['解除装夹', '表面工艺', '切割']: + if is_production_id is True: logging.info('product_qty:%s' % record.production_id.product_qty) for move_raw_id in record.production_id.move_raw_ids: move_raw_id.quantity_done = move_raw_id.product_uom_qty diff --git a/sf_plan/models/custom_plan.py b/sf_plan/models/custom_plan.py index f0214c9a..e7785ad4 100644 --- a/sf_plan/models/custom_plan.py +++ b/sf_plan/models/custom_plan.py @@ -231,26 +231,42 @@ class sf_production_plan(models.Model): if not record.production_line_id: raise ValidationError("未选择生产线") else: - 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) - # 没有工单也能排程 + # 自动化产线加工 + 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( + minutes=routing_workcenter.time_cycle) + item.date_planned_start = last_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.state = 'done' # record.production_id.schedule_state = '已排' record.sudo().production_id.schedule_state = '已排'