Skip to content

Commit 84ae0d0

Browse files
committed
extension without pushevents
1 parent e3da75b commit 84ae0d0

File tree

3 files changed

+124
-63
lines changed

3 files changed

+124
-63
lines changed

epictrack-api/src/api/actions/add_event.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ def get_additional_params(self, source_event: Event, params):
7676
del event_configuration["id"]
7777
event_configuration = EventConfiguration(**event_configuration)
7878
event_configuration.flush()
79-
# event_configuration_json = EventConfigurationResponseSchema().dump(
80-
# event_configuration
81-
# )
8279
WorkService.copy_outcome_and_actions(
8380
old_event_config.as_dict(recursive=False),
8481
event_configuration,

epictrack-api/src/api/services/event.py

Lines changed: 111 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -280,42 +280,17 @@ def _process_events(
280280
number_of_days_to_be_pushed = cls._get_number_of_days_to_be_pushed(
281281
event, event_old, current_work_phase
282282
)
283-
if (
284-
event.actual_date
285-
and event.event_configuration.event_position.value
286-
== EventPositionEnum.END.value
287-
):
288-
# set the numebr of days to the work phase phasestartdate - actual date
289-
cls._complete_work_phase(current_work_phase)
290-
if (
291-
event.event_configuration.event_position.value
292-
== EventPositionEnum.START.value
293-
):
294-
current_work_phase.start_date = cls._find_event_date(event)
295-
current_work_phase.update(
296-
current_work_phase.as_dict(recursive=False), commit=False
297-
)
298-
if (
299-
event.event_configuration.event_type_id
300-
== EventTypeEnum.TIME_LIMIT_SUSPENSION.value
301-
and event.actual_date
302-
):
303-
current_work_phase.suspended_date = event.actual_date
304-
current_work_phase.is_suspended = True
305-
current_work_phase.update(
306-
current_work_phase.as_dict(recursive=False), commit=False
307-
)
308-
if (
309-
event.event_configuration.event_type_id
310-
== EventTypeEnum.TIME_LIMIT_RESUMPTION.value
311-
and event.actual_date
312-
):
313-
event.number_of_days = number_of_days_to_be_pushed
314-
event.update(event.as_dict(recursive=False), commit=False)
315-
current_work_phase.is_suspended = False
316-
current_work_phase.update(
317-
current_work_phase.as_dict(recursive=False), commit=False
318-
)
283+
cls._handle_work_phase_for_end_phase_end_event(
284+
all_work_phases, current_work_phase_index, event, current_work_phase
285+
)
286+
cls._handle_work_phase_for_start_event(event, current_work_phase)
287+
cls._handle_work_phase_for_suspension(event, current_work_phase)
288+
cls._handle_work_phase_for_resumption(
289+
event, current_work_phase, number_of_days_to_be_pushed
290+
)
291+
cls._handle_work_phase_for_extension_without_push_events(
292+
event, current_work_phase, push_events, number_of_days_to_be_pushed
293+
)
319294

320295
current_event_index = cls.find_event_index(
321296
all_work_events, event_old if event_old else event, current_work_phase
@@ -385,6 +360,106 @@ def _process_events(
385360
current_event_index,
386361
)
387362

363+
@classmethod
364+
def _handle_work_phase_for_start_event(
365+
cls, event: Event, current_work_phase: WorkPhase
366+
) -> None:
367+
"""Update the work phase's start date if the start event's date changed"""
368+
if (
369+
event.event_configuration.event_position.value
370+
== EventPositionEnum.START.value
371+
):
372+
current_work_phase.start_date = cls._find_event_date(event)
373+
current_work_phase.update(
374+
current_work_phase.as_dict(recursive=False), commit=False
375+
)
376+
377+
@classmethod
378+
def _handle_work_phase_for_suspension(
379+
cls, event: Event, current_work_phase: WorkPhase
380+
) -> None:
381+
"""Update the work phase if the phase is suspended"""
382+
if (
383+
event.event_configuration.event_type_id
384+
== EventTypeEnum.TIME_LIMIT_SUSPENSION.value
385+
and event.actual_date
386+
):
387+
current_work_phase.suspended_date = event.actual_date
388+
current_work_phase.is_suspended = True
389+
current_work_phase.update(
390+
current_work_phase.as_dict(recursive=False), commit=False
391+
)
392+
393+
@classmethod
394+
def _handle_work_phase_for_resumption(
395+
cls,
396+
event: Event,
397+
current_work_phase: WorkPhase,
398+
number_of_days_to_be_pushed: int,
399+
) -> None:
400+
"""Update the work phase if the phase is resumed"""
401+
if (
402+
event.event_configuration.event_type_id
403+
== EventTypeEnum.TIME_LIMIT_RESUMPTION.value
404+
and event.actual_date
405+
):
406+
event.number_of_days = number_of_days_to_be_pushed
407+
event.update(event.as_dict(recursive=False), commit=False)
408+
current_work_phase.is_suspended = False
409+
current_work_phase.update(
410+
current_work_phase.as_dict(recursive=False), commit=False
411+
)
412+
413+
@classmethod
414+
def _handle_work_phase_for_end_phase_end_event(
415+
cls,
416+
all_work_phases: [WorkPhase],
417+
current_work_phase_index: int,
418+
event: Event,
419+
current_work_phase: WorkPhase,
420+
) -> None:
421+
"""Mark the current work phase complete and set the next work phase as the current one in the work"""
422+
if (
423+
event.actual_date
424+
and event.event_configuration.event_position.value
425+
== EventPositionEnum.END.value
426+
):
427+
current_work_phase.is_completed = True
428+
current_work_phase.update(
429+
current_work_phase.as_dict(recursive=False), commit=False
430+
)
431+
432+
work: Work = Work.find_by_id(current_work_phase.work_id)
433+
if current_work_phase_index == len(all_work_phases) - 1:
434+
work.work_state = WorkStateEnum.COMPLETED
435+
else:
436+
work.current_work_phase_id = all_work_phases[
437+
current_work_phase_index + 1
438+
].id
439+
work.update(work.as_dict(recursive=False), commit=False)
440+
441+
@classmethod
442+
def _handle_work_phase_for_extension_without_push_events(
443+
cls,
444+
event: Event,
445+
current_work_phase: WorkPhase,
446+
push_events: bool,
447+
number_of_days_to_be_pushed: int,
448+
) -> None:
449+
"""Update the work phase for extension with actual date and push events option as false"""
450+
if (
451+
event.event_configuration.event_category_id
452+
== EventCategoryEnum.EXTENSION.value
453+
and event.actual_date
454+
and not push_events
455+
):
456+
current_work_phase.end_date = current_work_phase.end_date + timedelta(
457+
days=number_of_days_to_be_pushed
458+
)
459+
current_work_phase.update(
460+
current_work_phase.as_dict(recursive=False), commit=False
461+
)
462+
388463
@classmethod
389464
def event_compare_func(cls, event_x, event_y):
390465
"""Compare function for event sort"""
@@ -452,29 +527,6 @@ def _find_event_index_in_array(cls, events: [Event], event_to_find: Event):
452527
break
453528
return index
454529

455-
@classmethod
456-
def _complete_work_phase(cls, current_work_phase: WorkPhase) -> None:
457-
"""Mark the current work phase complete and set the next work phase as the current one in the work"""
458-
all_work_phases = WorkPhase.find_by_params(
459-
{"work_id": current_work_phase.work_id}
460-
)
461-
current_work_phase.is_completed = True
462-
current_work_phase.update(
463-
current_work_phase.as_dict(recursive=False), commit=False
464-
)
465-
466-
current_work_phase_index = util.find_index_in_array(
467-
all_work_phases, current_work_phase
468-
)
469-
work: Work = Work.find_by_id(current_work_phase.work_id)
470-
if current_work_phase_index == len(all_work_phases) - 1:
471-
work.work_state = WorkStateEnum.COMPLETED
472-
else:
473-
work.current_work_phase_id = all_work_phases[
474-
current_work_phase_index + 1
475-
].id
476-
work.update(work.as_dict(recursive=False), commit=False)
477-
478530
@classmethod
479531
def _get_number_of_days_to_be_pushed(
480532
cls, event: Event, event_old: Event, current_work_phase: WorkPhase

epictrack-web/src/components/workPlan/event/EventForm.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,19 @@ const EventForm = ({
223223
[ctx.selectedWorkPhase, isStartEvent, isStartPhase]
224224
);
225225

226-
const actualDateMax = useMemo(() => dayjs(new Date()), []);
226+
const actualDateMax = useMemo(() => {
227+
if (ctx.selectedWorkPhase?.work_phase.legislated) {
228+
const diff = dayjs(ctx.selectedWorkPhase.work_phase.end_date).diff(
229+
ctx.selectedWorkPhase.work_phase.start_date,
230+
"day"
231+
);
232+
return dayjs(ctx.selectedWorkPhase.work_phase.start_date).add(
233+
diff,
234+
"day"
235+
);
236+
}
237+
return dayjs(new Date());
238+
}, [ctx.selectedWorkPhase]);
227239

228240
const methods = useForm({
229241
resolver: yupResolver(schema),

0 commit comments

Comments
 (0)