feat: 单工序多工段情况下平均分配

This commit is contained in:
caoqianming 2024-11-21 15:20:27 +08:00
parent 32158dfa77
commit 72b04ddc7a
1 changed files with 23 additions and 19 deletions

View File

@ -147,12 +147,15 @@ class PmService:
mgroups = Mgroup.objects.filter(process=val.process)
mgroups_count = mgroups.count()
if mgroups_count == 1:
mgroup = mgroups.first()
pass
elif mgroups_count == 0:
raise ParseError(f'{ind+1}步-工段不存在!')
else: # 后面可能会指定车间
raise ParseError(f'{ind+1}步-工段存在多个!')
else: # 存在同一工序的多个工段,先平均分配
pass
if schedule_type == 'to_day':
if mgroups_count > 1:
raise ParseError(f'{ind+1}步-工段存在多个!')
mgroup = mgroups.first()
task_count_day = math.ceil(count_task_list[ind]/rela_days)
if rela_days >= 1:
for i in range(rela_days):
@ -173,22 +176,23 @@ class PmService:
'is_count_utask': val.is_count_utask
})
elif schedule_type == 'to_mgroup':
Mtask.objects.create(**{
'route': val,
'number': f'{number}_r{ind+1}',
'type': utask.type,
'material_out': halfgood,
'material_in': material_in,
'mgroup': mgroup,
'count': count_task_list[ind],
'start_date': start_date,
'end_date': end_date,
'utask': utask,
'create_by': user,
'update_by': user,
'hour_work': val.hour_work,
'is_count_utask': val.is_count_utask
})
for indx, mgroup in enumerate(mgroups):
Mtask.objects.create(**{
'route': val,
'number': f'{number}_r{ind+1}_m{indx+1}',
'type': utask.type,
'material_out': halfgood,
'material_in': material_in,
'mgroup': mgroup,
'count': math.ceil(count_task_list[ind]/mgroups_count),
'start_date': start_date,
'end_date': end_date,
'utask': utask,
'create_by': user,
'update_by': user,
'hour_work': val.hour_work,
'is_count_utask': val.is_count_utask
})
else:
raise ParseError('不支持的排产类型')
@classmethod