修改排程逻辑
This commit is contained in:
@@ -219,7 +219,7 @@ class sf_production_plan(models.Model):
|
|||||||
|
|
||||||
return num
|
return num
|
||||||
|
|
||||||
def do_production_schedule(self, count=1):
|
def do_production_schedule(self):
|
||||||
"""
|
"""
|
||||||
排程方法
|
排程方法
|
||||||
"""
|
"""
|
||||||
@@ -227,29 +227,25 @@ class sf_production_plan(models.Model):
|
|||||||
if not record.production_line_id:
|
if not record.production_line_id:
|
||||||
raise ValidationError("未选择生产线")
|
raise ValidationError("未选择生产线")
|
||||||
else:
|
else:
|
||||||
is_schedule = self.deal_processing_schedule(record.date_planned_start, count)
|
if record.production_id.workorder_ids:
|
||||||
if not is_schedule:
|
last_cnc_finished = record.date_planned_start if record.date_planned_start else datetime.now()
|
||||||
raise ValidationError("排程失败")
|
for item in record.production_id.workorder_ids:
|
||||||
workorder_id_list = record.production_id.workorder_ids.ids
|
if item.name == 'CNC加工':
|
||||||
if record.production_id:
|
# 将同一个面的所有工单筛选出来
|
||||||
if record.production_id.workorder_ids:
|
workorder_list = record.production_id.workorder_ids.filtered(lambda x: x.processing_panel == item.processing_panel)
|
||||||
for item in record.production_id.workorder_ids:
|
routing_workcenter = record.env['mrp.routing.workcenter'].sudo().search(
|
||||||
if item.name == 'CNC加工':
|
[('name', '=', 'CNC加工')], limit=1)
|
||||||
item.date_planned_finished = datetime.now() + timedelta(days=100)
|
item.date_planned_finished = last_cnc_finished + timedelta(
|
||||||
item.date_planned_start = self.date_planned_start if self.date_planned_start else datetime.now()
|
minutes=routing_workcenter.time_cycle)
|
||||||
record.sudo().production_id.plan_start_processing_time = item.date_planned_start
|
item.date_planned_start = last_cnc_finished
|
||||||
item.date_planned_finished = item.date_planned_start + timedelta(
|
record.sudo().production_id.plan_start_processing_time = item.date_planned_start
|
||||||
minutes=record.env['mrp.routing.workcenter'].sudo().search(
|
item.duration_expected = routing_workcenter.time_cycle
|
||||||
[('name', '=', 'CNC加工')]).time_cycle)
|
record.calculate_plan_time(item, workorder_list)
|
||||||
item.duration_expected = record.env['mrp.routing.workcenter'].sudo().search(
|
# record.calculate_plan_time_before1(item, record.production_id.workorder_ids)
|
||||||
[('name', '=', 'CNC加工')]).time_cycle
|
record.calculate_plan_time_after(item, workorder_id_list)
|
||||||
record.calculate_plan_time_before(item, workorder_id_list)
|
record.date_planned_finished = item.date_planned_finished
|
||||||
record.calculate_plan_time_after(item, workorder_id_list)
|
last_cnc_finished = item.date_planned_finished
|
||||||
record.date_planned_start, record.date_planned_finished = \
|
|
||||||
item.date_planned_start, item.date_planned_finished
|
|
||||||
record.state = 'done'
|
record.state = 'done'
|
||||||
record.date_planned_finished = record.date_planned_start + timedelta(
|
|
||||||
minutes=60) if not record.date_planned_finished else record.date_planned_finished
|
|
||||||
# record.production_id.schedule_state = '已排'
|
# record.production_id.schedule_state = '已排'
|
||||||
record.sudo().production_id.schedule_state = '已排'
|
record.sudo().production_id.schedule_state = '已排'
|
||||||
record.sudo().production_id.process_state = '待装夹'
|
record.sudo().production_id.process_state = '待装夹'
|
||||||
@@ -282,54 +278,86 @@ class sf_production_plan(models.Model):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# 处理是否可排程
|
# 处理是否可排程
|
||||||
def deal_processing_schedule(self, date_planned_start, count):
|
def deal_processing_schedule(self, date_planned_start,):
|
||||||
for record in self:
|
count = len(self)
|
||||||
workcenter_ids = record.production_line_id.mrp_workcenter_ids
|
workcenter_ids = self.production_line_id.mrp_workcenter_ids
|
||||||
if not workcenter_ids:
|
if not workcenter_ids:
|
||||||
raise UserError('生产线没有配置工作中心')
|
raise UserError('生产线没有配置工作中心')
|
||||||
production_lines = workcenter_ids.filtered(lambda b: "自动生产线" in b.name)
|
production_lines = workcenter_ids.filtered(lambda b: "自动生产线" in b.name)
|
||||||
if not production_lines: # 判断是否配置了自动生产线
|
if not production_lines: # 判断是否配置了自动生产线
|
||||||
raise UserError('生产线没有配置自动生产线')
|
raise UserError('生产线没有配置自动生产线')
|
||||||
if date_planned_start < datetime.now(): # 判断计划开始时间是否小于当前时间
|
if date_planned_start < datetime.now(): # 判断计划开始时间是否小于当前时间
|
||||||
raise UserError('计划开始时间不能小于当前时间')
|
raise UserError('计划开始时间不能小于当前时间')
|
||||||
if all(not production_line.deal_with_workcenter_calendar(date_planned_start) for production_line in
|
if all(not production_line.deal_with_workcenter_calendar(date_planned_start) for production_line in
|
||||||
production_lines): # 判断计划开始时间是否在配置的工作中心的工作日历内
|
production_lines): # 判断计划开始时间是否在配置的工作中心的工作日历内
|
||||||
raise UserError('当前计划开始时间不能预约排程,请在工作时间内排程')
|
raise UserError('当前计划开始时间不能预约排程,请在工作时间内排程')
|
||||||
if not production_lines.deal_available_default_capacity(date_planned_start): # 判断生产线是否可排程
|
if not production_lines.deal_available_default_capacity(date_planned_start): # 判断生产线是否可排程
|
||||||
raise UserError('当前计划开始时间不能预约排程,生产线今日没有可排程的资源')
|
raise UserError('当前计划开始时间不能预约排程,生产线今日没有可排程的资源')
|
||||||
if not production_lines.deal_available_single_machine_capacity(date_planned_start, count): # 判断生产线是否可排程
|
if not production_lines.deal_available_single_machine_capacity(date_planned_start, count): # 判断生产线是否可排程
|
||||||
raise UserError('当前计划开始时间不能预约排程,生产线该时间段没有可排程的资源')
|
raise UserError('当前计划开始时间不能预约排程,生产线该时间段没有可排程的资源')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def calculate_plan_time_before(self, item, workorder_id_list):
|
def calculate_plan_time(self, item, workorder_list):
|
||||||
"""
|
"""
|
||||||
根据CNC工单的时间去计算之前的其他工单的开始结束时间
|
根据CNC工单的时间去计算之前的其他工单的开始结束时间
|
||||||
"""
|
"""
|
||||||
sequence = workorder_id_list.index(item.id) - 1
|
item_position = 0
|
||||||
# 计算CNC加工之前工单的开始结束时间
|
for index, workorder in enumerate(workorder_list):
|
||||||
for i in range(1 if sequence == 0 else sequence):
|
if workorder.id == item.id:
|
||||||
current_workorder_id = (item.id - (i + 1))
|
item_position = index
|
||||||
current_workorder_obj = self.env['mrp.workorder'].sudo().search(
|
break
|
||||||
[('id', '=', current_workorder_id)])
|
routing_workcenters = self.env['mrp.routing.workcenter'].sudo().search([])
|
||||||
old_workorder_obj = self.env['mrp.workorder'].sudo().search(
|
# 记录所有前序工序时长
|
||||||
[('id', '=', (current_workorder_id + 1))])
|
previous_workorder_duration = 0
|
||||||
work_order = self.env['mrp.workorder'].sudo().search(
|
for i in range(item_position, -1, -1):
|
||||||
[('production_id', '=', self.production_id.id), ('id', '=', current_workorder_id)])
|
if i < 1:
|
||||||
work_order.date_planned_finished = datetime.now() + timedelta(days=100)
|
break
|
||||||
work_order.date_planned_start = old_workorder_obj.date_planned_start - timedelta(
|
current_workorder = workorder_list[i]
|
||||||
minutes=self.env['mrp.routing.workcenter'].sudo().search(
|
next_workorder = workorder_list[i - 1]
|
||||||
[('name', '=', current_workorder_obj.name)]).time_cycle)
|
routing_workcenter = routing_workcenters.filtered(lambda x: x.name == next_workorder.name)[0]
|
||||||
work_order.date_planned_finished = old_workorder_obj.date_planned_start
|
next_workorder.date_planned_finished = current_workorder.date_planned_start
|
||||||
work_order.duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
|
next_workorder.date_planned_start = next_workorder.date_planned_finished - timedelta(
|
||||||
[('name', '=', current_workorder_obj.name)]).time_cycle
|
minutes=routing_workcenter.time_cycle)
|
||||||
first_workorder = self.env['mrp.workorder'].sudo().search([('id', '=', workorder_id_list[0])])
|
next_workorder.duration_expected = routing_workcenter.time_cycle
|
||||||
second_workorder = self.env['mrp.workorder'].sudo().search([('id', '=', workorder_id_list[1])])
|
previous_workorder_duration += routing_workcenter.time_cycle
|
||||||
if second_workorder.date_planned_start < first_workorder.date_planned_finished:
|
# 记录所有后续工序时长
|
||||||
item.date_planned_start += timedelta(minutes=60)
|
next_workorder_duration = 0
|
||||||
item.date_planned_finished += timedelta(minutes=60)
|
for i in range(item_position + 1, len(workorder_list)):
|
||||||
item.duration_expected = self.env['mrp.routing.workcenter'].sudo().search(
|
if i > len(workorder_list) - 1:
|
||||||
[('name', '=', 'CNC加工')]).time_cycle
|
break
|
||||||
self.calculate_plan_time_before(item, workorder_id_list)
|
current_workorder = workorder_list[i]
|
||||||
|
next_workorder = workorder_list[i + 1]
|
||||||
|
routing_workcenter = routing_workcenters.filtered(lambda x: x.name == next_workorder.name)[0]
|
||||||
|
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
|
||||||
|
# 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)
|
||||||
|
|
||||||
def calculate_plan_time_after(self, item, workorder_id_list):
|
def calculate_plan_time_after(self, item, workorder_id_list):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -31,22 +31,24 @@ class Action_Plan_All_Wizard(models.TransientModel):
|
|||||||
# 确认排程按钮
|
# 确认排程按钮
|
||||||
def action_plan_all(self):
|
def action_plan_all(self):
|
||||||
# 使用传递过来的计划ID
|
# 使用传递过来的计划ID
|
||||||
temp_plan_ids = self.plan_ids
|
self.plan_ids.production_line_id = self.production_line_id.id
|
||||||
|
self.plan_ids.date_planned_start = self.date_planned_start
|
||||||
# 在这里添加您的逻辑来处理这些ID
|
# 在这里添加您的逻辑来处理这些ID
|
||||||
count = len(temp_plan_ids) + 1
|
# 判断能否排成
|
||||||
for plan in temp_plan_ids:
|
self.plan_ids.deal_processing_schedule(self.date_planned_start)
|
||||||
count = count - 1
|
self.plan_ids.do_production_schedule()
|
||||||
# 处理每个计划
|
# for plan in temp_plan_ids:
|
||||||
# 比如更新计划状态、分配资源等
|
# # 处理每个计划
|
||||||
# 示例:plan.state = 'scheduled'
|
# # 比如更新计划状态、分配资源等
|
||||||
print('处理计划:', plan.id)
|
# # 示例:plan.state = 'scheduled'
|
||||||
# 拿到计划对象
|
# print('处理计划:', plan.id)
|
||||||
plan_obj = self.env['sf.production.plan'].browse(plan.id)
|
# # 拿到计划对象
|
||||||
plan_obj.production_line_id = self.production_line_id.id
|
# plan_obj = self.env['sf.production.plan'].browse(plan.id)
|
||||||
plan.date_planned_start = self.date_planned_start
|
# plan_obj.production_line_id = self.production_line_id.id
|
||||||
plan_obj.do_production_schedule(count)
|
# plan.date_planned_start = self.date_planned_start
|
||||||
|
# plan_obj.do_production_schedule()
|
||||||
# plan_obj.state = 'done'
|
# plan_obj.state = 'done'
|
||||||
print('处理计划:', plan.id, '完成')
|
print('处理计划:', self.plan_ids.id, '完成')
|
||||||
|
|
||||||
# # 获取当前生产线
|
# # 获取当前生产线
|
||||||
# production_line_id = self.production_line_id
|
# production_line_id = self.production_line_id
|
||||||
|
|||||||
Reference in New Issue
Block a user