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