修改计划排程,超过小时产能提示产线的小时产能以及超出的件数

This commit is contained in:
hujiaying
2024-10-10 16:47:25 +08:00
parent d1ff7c196d
commit 50bb50f5ab
3 changed files with 16 additions and 9 deletions

View File

@@ -237,7 +237,7 @@ class ResWorkcenter(models.Model):
return True
# 处理排程是否超过小时产能
def deal_available_single_machine_capacity(self, date_planned):
def deal_available_single_machine_capacity(self, date_planned, count):
date_planned_start = date_planned.strftime('%Y-%m-%d %H:00:00')
date_planned_end = date_planned + timedelta(hours=1)
@@ -249,7 +249,11 @@ class ResWorkcenter(models.Model):
if plan_ids:
sum_qty = sum([p.product_qty for p in plan_ids])
if sum_qty >= self.production_line_hour_capacity:
production_line_hour_capacity = self.production_line_hour_capacity
if sum_qty >= production_line_hour_capacity:
message = '当前计划开始时间不能预约排程,超过生产线小时产能(%d件)%d' % (
production_line_hour_capacity, count)
raise UserError(message)
return False
return True

View File

@@ -90,6 +90,7 @@ class sf_production_plan(models.Model):
for item in plans:
if item.date_planned_start:
item.order_deadline = item.date_planned_start + timedelta(days=7)
@api.model
def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None):
@@ -218,7 +219,7 @@ class sf_production_plan(models.Model):
return num
def do_production_schedule(self):
def do_production_schedule(self, count=1):
"""
排程方法
"""
@@ -226,7 +227,7 @@ class sf_production_plan(models.Model):
if not record.production_line_id:
raise ValidationError("未选择生产线")
else:
is_schedule = self.deal_processing_schedule(record.date_planned_start)
is_schedule = self.deal_processing_schedule(record.date_planned_start, count)
if not is_schedule:
raise ValidationError("排程失败")
workorder_id_list = record.production_id.workorder_ids.ids
@@ -281,7 +282,7 @@ class sf_production_plan(models.Model):
}
# 处理是否可排程
def deal_processing_schedule(self, date_planned_start):
def deal_processing_schedule(self, date_planned_start, count):
for record in self:
workcenter_ids = record.production_line_id.mrp_workcenter_ids
if not workcenter_ids:
@@ -296,7 +297,7 @@ class sf_production_plan(models.Model):
raise UserError('当前计划开始时间不能预约排程,请在工作时间内排程')
if not production_lines.deal_available_default_capacity(date_planned_start): # 判断生产线是否可排程
raise UserError('当前计划开始时间不能预约排程,生产线今日没有可排程的资源')
if not production_lines.deal_available_single_machine_capacity(date_planned_start): # 判断生产线是否可排程
if not production_lines.deal_available_single_machine_capacity(date_planned_start, count): # 判断生产线是否可排程
raise UserError('当前计划开始时间不能预约排程,生产线该时间段没有可排程的资源')
return True

View File

@@ -33,7 +33,9 @@ class Action_Plan_All_Wizard(models.TransientModel):
# 使用传递过来的计划ID
temp_plan_ids = self.plan_ids
# 在这里添加您的逻辑来处理这些ID
count = len(temp_plan_ids) + 1
for plan in temp_plan_ids:
count = count - 1
# 处理每个计划
# 比如更新计划状态、分配资源等
# 示例plan.state = 'scheduled'
@@ -42,7 +44,7 @@ class Action_Plan_All_Wizard(models.TransientModel):
plan_obj = self.env['sf.production.plan'].browse(plan.id)
plan_obj.production_line_id = self.production_line_id.id
plan.date_planned_start = self.date_planned_start
plan_obj.do_production_schedule()
plan_obj.do_production_schedule(count)
# plan_obj.state = 'done'
print('处理计划:', plan.id, '完成')