修改排程逻辑
This commit is contained in:
@@ -228,23 +228,22 @@ class sf_production_plan(models.Model):
|
||||
raise ValidationError("未选择生产线")
|
||||
else:
|
||||
if record.production_id.workorder_ids:
|
||||
last_cnc_finished = record.date_planned_start if record.date_planned_start else datetime.now()
|
||||
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_finished = last_cnc_finished + timedelta(
|
||||
item.date_planned_finished = last_cnc_start + timedelta(
|
||||
minutes=routing_workcenter.time_cycle)
|
||||
item.date_planned_start = last_cnc_finished
|
||||
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
|
||||
record.calculate_plan_time(item, workorder_list)
|
||||
# record.calculate_plan_time_before1(item, record.production_id.workorder_ids)
|
||||
record.calculate_plan_time_after(item, workorder_id_list)
|
||||
pre_duration , next_duration = record.calculate_plan_time(item, workorder_list)
|
||||
record.date_planned_finished = item.date_planned_finished
|
||||
last_cnc_finished = item.date_planned_finished
|
||||
# 计算下一个cnc工单的开始时间
|
||||
last_cnc_start = workorder_list[-1].date_planned_finished + timedelta(minutes=pre_duration)
|
||||
record.state = 'done'
|
||||
# record.production_id.schedule_state = '已排'
|
||||
record.sudo().production_id.schedule_state = '已排'
|
||||
@@ -322,7 +321,7 @@ class sf_production_plan(models.Model):
|
||||
previous_workorder_duration += routing_workcenter.time_cycle
|
||||
# 记录所有后续工序时长
|
||||
next_workorder_duration = 0
|
||||
for i in range(item_position + 1, len(workorder_list)):
|
||||
for i in range(item_position, len(workorder_list) - 1):
|
||||
if i > len(workorder_list) - 1:
|
||||
break
|
||||
current_workorder = workorder_list[i]
|
||||
@@ -333,31 +332,7 @@ class sf_production_plan(models.Model):
|
||||
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
|
||||
# sequence = item_position - 1
|
||||
# # 计算CNC加工之前工单的开始结束时间
|
||||
# for i in range(1 if sequence == 0 else sequence):
|
||||
# current_workorder_id = (item.id - (i + 1))
|
||||
# current_workorder_obj = self.env['mrp.workorder'].sudo().search(
|
||||
# [('id', '=', current_workorder_id)])
|
||||
# old_workorder_obj = self.env['mrp.workorder'].sudo().search(
|
||||
# [('id', '=', (current_workorder_id + 1))])
|
||||
# work_order = self.env['mrp.workorder'].sudo().search(
|
||||
# [('production_id', '=', self.production_id.id), ('id', '=', current_workorder_id)])
|
||||
# work_order.date_planned_finished = datetime.now() + timedelta(days=100)
|
||||
# work_order.date_planned_start = old_workorder_obj.date_planned_start - timedelta(
|
||||
# minutes=self.env['mrp.routing.workcenter'].sudo().search(
|
||||
# [('name', '=', current_workorder_obj.name)]).time_cycle)
|
||||
# work_order.date_planned_finished = old_workorder_obj.date_planned_start
|
||||
# work_order.duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
|
||||
# [('name', '=', current_workorder_obj.name)]).time_cycle
|
||||
# first_workorder = self.env['mrp.workorder'].sudo().search([('id', '=', workorder_id_list[0])])
|
||||
# second_workorder = self.env['mrp.workorder'].sudo().search([('id', '=', workorder_id_list[1])])
|
||||
# if second_workorder.date_planned_start < first_workorder.date_planned_finished:
|
||||
# item.date_planned_start += timedelta(minutes=60)
|
||||
# item.date_planned_finished += timedelta(minutes=60)
|
||||
# item.duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
|
||||
# [('name', '=', 'CNC加工')]).time_cycle
|
||||
# self.calculate_plan_time_before(item, workorder_id_list)
|
||||
return previous_workorder_duration, next_workorder_duration
|
||||
|
||||
def calculate_plan_time_after(self, item, workorder_id_list):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user