修改计划排程,超过小时产能提示产线的小时产能以及超出的件数
This commit is contained in:
@@ -231,13 +231,13 @@ class ResWorkcenter(models.Model):
|
|||||||
default_capacity = round(
|
default_capacity = round(
|
||||||
self.production_line_hour_capacity * date_planned_working_hours, 2)
|
self.production_line_hour_capacity * date_planned_working_hours, 2)
|
||||||
_logger.info('排程日期:%s,计划数量:%s,日产能:%s,日工时:%s' % (
|
_logger.info('排程日期:%s,计划数量:%s,日产能:%s,日工时:%s' % (
|
||||||
date_planned, sum_qty, default_capacity, date_planned_working_hours))
|
date_planned, sum_qty, default_capacity, date_planned_working_hours))
|
||||||
if sum_qty >= default_capacity:
|
if sum_qty >= default_capacity:
|
||||||
return False
|
return False
|
||||||
return True
|
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_start = date_planned.strftime('%Y-%m-%d %H:00:00')
|
||||||
date_planned_end = date_planned + timedelta(hours=1)
|
date_planned_end = date_planned + timedelta(hours=1)
|
||||||
@@ -249,7 +249,11 @@ class ResWorkcenter(models.Model):
|
|||||||
|
|
||||||
if plan_ids:
|
if plan_ids:
|
||||||
sum_qty = sum([p.product_qty for p in 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 False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class sf_production_plan(models.Model):
|
|||||||
if self.date_planned_start:
|
if self.date_planned_start:
|
||||||
self.date_planned_finished = self.date_planned_start + timedelta(hours=1)
|
self.date_planned_finished = self.date_planned_start + timedelta(hours=1)
|
||||||
|
|
||||||
#处理计划状态非待排程,计划结束时间为空的数据处理
|
# 处理计划状态非待排程,计划结束时间为空的数据处理
|
||||||
def deal_no_date_planned_finished(self):
|
def deal_no_date_planned_finished(self):
|
||||||
plans = self.env['sf.production.plan'].search(
|
plans = self.env['sf.production.plan'].search(
|
||||||
[('date_planned_finished', '=', False), ('state', 'in', ['processing', 'done', 'finished'])])
|
[('date_planned_finished', '=', False), ('state', 'in', ['processing', 'done', 'finished'])])
|
||||||
@@ -90,6 +90,7 @@ class sf_production_plan(models.Model):
|
|||||||
for item in plans:
|
for item in plans:
|
||||||
if item.date_planned_start:
|
if item.date_planned_start:
|
||||||
item.order_deadline = item.date_planned_start + timedelta(days=7)
|
item.order_deadline = item.date_planned_start + timedelta(days=7)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None):
|
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
|
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:
|
if not record.production_line_id:
|
||||||
raise ValidationError("未选择生产线")
|
raise ValidationError("未选择生产线")
|
||||||
else:
|
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:
|
if not is_schedule:
|
||||||
raise ValidationError("排程失败")
|
raise ValidationError("排程失败")
|
||||||
workorder_id_list = record.production_id.workorder_ids.ids
|
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:
|
for record in self:
|
||||||
workcenter_ids = record.production_line_id.mrp_workcenter_ids
|
workcenter_ids = record.production_line_id.mrp_workcenter_ids
|
||||||
if not workcenter_ids:
|
if not workcenter_ids:
|
||||||
@@ -296,7 +297,7 @@ class sf_production_plan(models.Model):
|
|||||||
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): # 判断生产线是否可排程
|
if not production_lines.deal_available_single_machine_capacity(date_planned_start, count): # 判断生产线是否可排程
|
||||||
raise UserError('当前计划开始时间不能预约排程,生产线该时间段没有可排程的资源')
|
raise UserError('当前计划开始时间不能预约排程,生产线该时间段没有可排程的资源')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ class Action_Plan_All_Wizard(models.TransientModel):
|
|||||||
# 使用传递过来的计划ID
|
# 使用传递过来的计划ID
|
||||||
temp_plan_ids = self.plan_ids
|
temp_plan_ids = self.plan_ids
|
||||||
# 在这里添加您的逻辑来处理这些ID
|
# 在这里添加您的逻辑来处理这些ID
|
||||||
|
count = len(temp_plan_ids) + 1
|
||||||
for plan in temp_plan_ids:
|
for plan in temp_plan_ids:
|
||||||
|
count = count - 1
|
||||||
# 处理每个计划
|
# 处理每个计划
|
||||||
# 比如更新计划状态、分配资源等
|
# 比如更新计划状态、分配资源等
|
||||||
# 示例:plan.state = 'scheduled'
|
# 示例: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 = self.env['sf.production.plan'].browse(plan.id)
|
||||||
plan_obj.production_line_id = self.production_line_id.id
|
plan_obj.production_line_id = self.production_line_id.id
|
||||||
plan.date_planned_start = self.date_planned_start
|
plan.date_planned_start = self.date_planned_start
|
||||||
plan_obj.do_production_schedule()
|
plan_obj.do_production_schedule(count)
|
||||||
# plan_obj.state = 'done'
|
# plan_obj.state = 'done'
|
||||||
print('处理计划:', plan.id, '完成')
|
print('处理计划:', plan.id, '完成')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user