修改排程

This commit is contained in:
胡尧
2024-11-28 15:10:45 +08:00
parent f1e70d2c66
commit 96171013d6

View File

@@ -232,41 +232,37 @@ class sf_production_plan(models.Model):
raise ValidationError("未选择生产线") raise ValidationError("未选择生产线")
else: else:
# 自动化产线加工 # 自动化产线加工
if record.production_id.production_type == '自动化产线加工':
if record.production_id.workorder_ids: 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 record.production_id.production_type == '自动化产线加工':
if item.name == 'CNC加工': # 找到第一张CNC加工工单
# 将同一个面的所有工单筛选出来 first_cnc_workorder = record.production_id.workorder_ids.filtered(lambda x: x.name == 'CNC加工')[0]
workorder_list = record.production_id.workorder_ids.filtered(lambda x: x.processing_panel == item.processing_panel) date_start = record.date_planned_start if record.date_planned_start else datetime.now()
routing_workcenter = record.env['mrp.routing.workcenter'].sudo().search( routing_workcenter = first_cnc_workorder.technology_design_id.route_id
[('name', '=', 'CNC加工')], limit=1)
# 设置一个小的开始时间 # 设置一个小的开始时间
item.date_planned_start = datetime.now() - timedelta(days=100) first_cnc_workorder.date_planned_start = datetime.now() - timedelta(days=100)
item.date_planned_finished = last_cnc_start + timedelta( first_cnc_workorder.date_planned_finished = date_start + timedelta(
minutes=routing_workcenter.time_cycle) minutes=routing_workcenter.time_cycle)
item.date_planned_start = last_cnc_start first_cnc_workorder.date_planned_start = date_start
record.sudo().production_id.plan_start_processing_time = item.date_planned_start record.sudo().production_id.plan_start_processing_time = first_cnc_workorder.date_planned_start
item.duration_expected = routing_workcenter.time_cycle first_cnc_workorder.duration_expected = routing_workcenter.time_cycle
pre_duration , next_duration = record.calculate_plan_time(item, workorder_list) record.calculate_plan_time(first_cnc_workorder, record.production_id.workorder_ids)
record.date_planned_finished = item.date_planned_finished # 找到最后一张CNC加工工单
# 计算下一个cnc工单的开始时间 last_cnc_workorder = record.production_id.workorder_ids.filtered(lambda x: x.name == 'CNC加工')[-1]
last_cnc_start = workorder_list[-1].date_planned_finished + timedelta(minutes=pre_duration) record.date_planned_finished = last_cnc_workorder.date_planned_finished
# 没有工单也能排程
else: else:
# 人工线下加工只排第一张工单 # 人工线下加工只排第一张工单
if record.production_id.workorder_ids:
item = record.production_id.workorder_ids[0] item = record.production_id.workorder_ids[0]
last_wo_start = record.date_planned_start if record.date_planned_start else datetime.now() 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_start = datetime.now() - timedelta(days=100)
item.date_planned_finished = last_wo_start + timedelta( item.date_planned_finished = wo_start + timedelta(
minutes=routing_workcenter.time_cycle) minutes=routing_workcenter.time_cycle)
item.date_planned_start = last_wo_start item.date_planned_start = wo_start
record.sudo().production_id.plan_start_processing_time = item.date_planned_start record.sudo().production_id.plan_start_processing_time = item.date_planned_start
item.duration_expected = routing_workcenter.time_cycle 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.state = 'done'
# record.production_id.schedule_state = '已排' # record.production_id.schedule_state = '已排'
record.sudo().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: if workorder.id == item.id:
item_position = index item_position = index
break break
routing_workcenters = self.env['mrp.routing.workcenter'].sudo().search([])
# 记录所有前序工序时长
previous_workorder_duration = 0
for i in range(item_position, -1, -1): for i in range(item_position, -1, -1):
if i < 1: if i < 1:
break break
current_workorder = workorder_list[i] current_workorder = workorder_list[i]
next_workorder = workorder_list[i - 1] 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_start = datetime.now() - timedelta(days=100)
next_workorder.date_planned_finished = current_workorder.date_planned_start next_workorder.date_planned_finished = current_workorder.date_planned_start
next_workorder.date_planned_start = next_workorder.date_planned_finished - timedelta( next_workorder.date_planned_start = next_workorder.date_planned_finished - timedelta(
minutes=routing_workcenter.time_cycle) minutes=routing_workcenter.time_cycle)
next_workorder.duration_expected = 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): for i in range(item_position, len(workorder_list) - 1):
if i > len(workorder_list) - 1: if i > len(workorder_list) - 1:
break break
current_workorder = workorder_list[i] current_workorder = workorder_list[i]
next_workorder = workorder_list[i + 1] 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_start = datetime.now() - timedelta(days=100)
next_workorder.date_planned_finished = current_workorder.date_planned_finished + timedelta( next_workorder.date_planned_finished = current_workorder.date_planned_finished + timedelta(
minutes=routing_workcenter.time_cycle) minutes=routing_workcenter.time_cycle)
next_workorder.date_planned_start = current_workorder.date_planned_finished next_workorder.date_planned_start = current_workorder.date_planned_finished
next_workorder.duration_expected = routing_workcenter.time_cycle 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): def calculate_plan_time_after(self, item, workorder_id_list):
""" """