修改排程
This commit is contained in:
@@ -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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user