Skip to content

Commit

Permalink
Merge pull request #1456 from dinesh-aot/1390
Browse files Browse the repository at this point in the history
EndEvent actual date max limit based on the extension milestone
  • Loading branch information
jadmsaadaot authored Dec 15, 2023
2 parents cae4376 + 4f208d5 commit fb57608
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 63 deletions.
3 changes: 0 additions & 3 deletions epictrack-api/src/api/actions/add_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ def get_additional_params(self, source_event: Event, params):
del event_configuration["id"]
event_configuration = EventConfiguration(**event_configuration)
event_configuration.flush()
# event_configuration_json = EventConfigurationResponseSchema().dump(
# event_configuration
# )
WorkService.copy_outcome_and_actions(
old_event_config.as_dict(recursive=False),
event_configuration,
Expand Down
170 changes: 111 additions & 59 deletions epictrack-api/src/api/services/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,42 +280,17 @@ def _process_events(
number_of_days_to_be_pushed = cls._get_number_of_days_to_be_pushed(
event, event_old, current_work_phase
)
if (
event.actual_date
and event.event_configuration.event_position.value
== EventPositionEnum.END.value
):
# set the numebr of days to the work phase phasestartdate - actual date
cls._complete_work_phase(current_work_phase)
if (
event.event_configuration.event_position.value
== EventPositionEnum.START.value
):
current_work_phase.start_date = cls._find_event_date(event)
current_work_phase.update(
current_work_phase.as_dict(recursive=False), commit=False
)
if (
event.event_configuration.event_type_id
== EventTypeEnum.TIME_LIMIT_SUSPENSION.value
and event.actual_date
):
current_work_phase.suspended_date = event.actual_date
current_work_phase.is_suspended = True
current_work_phase.update(
current_work_phase.as_dict(recursive=False), commit=False
)
if (
event.event_configuration.event_type_id
== EventTypeEnum.TIME_LIMIT_RESUMPTION.value
and event.actual_date
):
event.number_of_days = number_of_days_to_be_pushed
event.update(event.as_dict(recursive=False), commit=False)
current_work_phase.is_suspended = False
current_work_phase.update(
current_work_phase.as_dict(recursive=False), commit=False
)
cls._handle_work_phase_for_end_phase_end_event(
all_work_phases, current_work_phase_index, event, current_work_phase
)
cls._handle_work_phase_for_start_event(event, current_work_phase)
cls._handle_work_phase_for_suspension(event, current_work_phase)
cls._handle_work_phase_for_resumption(
event, current_work_phase, number_of_days_to_be_pushed
)
cls._handle_work_phase_for_extension_without_push_events(
event, current_work_phase, push_events, number_of_days_to_be_pushed
)

current_event_index = cls.find_event_index(
all_work_events, event_old if event_old else event, current_work_phase
Expand Down Expand Up @@ -385,6 +360,106 @@ def _process_events(
current_event_index,
)

@classmethod
def _handle_work_phase_for_start_event(
cls, event: Event, current_work_phase: WorkPhase
) -> None:
"""Update the work phase's start date if the start event's date changed"""
if (
event.event_configuration.event_position.value
== EventPositionEnum.START.value
):
current_work_phase.start_date = cls._find_event_date(event)
current_work_phase.update(
current_work_phase.as_dict(recursive=False), commit=False
)

@classmethod
def _handle_work_phase_for_suspension(
cls, event: Event, current_work_phase: WorkPhase
) -> None:
"""Update the work phase if the phase is suspended"""
if (
event.event_configuration.event_type_id
== EventTypeEnum.TIME_LIMIT_SUSPENSION.value
and event.actual_date
):
current_work_phase.suspended_date = event.actual_date
current_work_phase.is_suspended = True
current_work_phase.update(
current_work_phase.as_dict(recursive=False), commit=False
)

@classmethod
def _handle_work_phase_for_resumption(
cls,
event: Event,
current_work_phase: WorkPhase,
number_of_days_to_be_pushed: int,
) -> None:
"""Update the work phase if the phase is resumed"""
if (
event.event_configuration.event_type_id
== EventTypeEnum.TIME_LIMIT_RESUMPTION.value
and event.actual_date
):
event.number_of_days = number_of_days_to_be_pushed
event.update(event.as_dict(recursive=False), commit=False)
current_work_phase.is_suspended = False
current_work_phase.update(
current_work_phase.as_dict(recursive=False), commit=False
)

@classmethod
def _handle_work_phase_for_end_phase_end_event(
cls,
all_work_phases: [WorkPhase],
current_work_phase_index: int,
event: Event,
current_work_phase: WorkPhase,
) -> None:
"""Mark the current work phase complete and set the next work phase as the current one in the work"""
if (
event.actual_date
and event.event_configuration.event_position.value
== EventPositionEnum.END.value
):
current_work_phase.is_completed = True
current_work_phase.update(
current_work_phase.as_dict(recursive=False), commit=False
)

work: Work = Work.find_by_id(current_work_phase.work_id)
if current_work_phase_index == len(all_work_phases) - 1:
work.work_state = WorkStateEnum.COMPLETED
else:
work.current_work_phase_id = all_work_phases[
current_work_phase_index + 1
].id
work.update(work.as_dict(recursive=False), commit=False)

@classmethod
def _handle_work_phase_for_extension_without_push_events(
cls,
event: Event,
current_work_phase: WorkPhase,
push_events: bool,
number_of_days_to_be_pushed: int,
) -> None:
"""Update the work phase for extension with actual date and push events option as false"""
if (
event.event_configuration.event_category_id
== EventCategoryEnum.EXTENSION.value
and event.actual_date
and not push_events
):
current_work_phase.end_date = current_work_phase.end_date + timedelta(
days=number_of_days_to_be_pushed
)
current_work_phase.update(
current_work_phase.as_dict(recursive=False), commit=False
)

@classmethod
def event_compare_func(cls, event_x, event_y):
"""Compare function for event sort"""
Expand Down Expand Up @@ -452,29 +527,6 @@ def _find_event_index_in_array(cls, events: [Event], event_to_find: Event):
break
return index

@classmethod
def _complete_work_phase(cls, current_work_phase: WorkPhase) -> None:
"""Mark the current work phase complete and set the next work phase as the current one in the work"""
all_work_phases = WorkPhase.find_by_params(
{"work_id": current_work_phase.work_id}
)
current_work_phase.is_completed = True
current_work_phase.update(
current_work_phase.as_dict(recursive=False), commit=False
)

current_work_phase_index = util.find_index_in_array(
all_work_phases, current_work_phase
)
work: Work = Work.find_by_id(current_work_phase.work_id)
if current_work_phase_index == len(all_work_phases) - 1:
work.work_state = WorkStateEnum.COMPLETED
else:
work.current_work_phase_id = all_work_phases[
current_work_phase_index + 1
].id
work.update(work.as_dict(recursive=False), commit=False)

@classmethod
def _get_number_of_days_to_be_pushed(
cls, event: Event, event_old: Event, current_work_phase: WorkPhase
Expand Down
14 changes: 13 additions & 1 deletion epictrack-web/src/components/workPlan/event/EventForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,19 @@ const EventForm = ({
[ctx.selectedWorkPhase, isStartEvent, isStartPhase]
);

const actualDateMax = useMemo(() => dayjs(new Date()), []);
const actualDateMax = useMemo(() => {
if (ctx.selectedWorkPhase?.work_phase.legislated) {
const diff = dayjs(ctx.selectedWorkPhase.work_phase.end_date).diff(
ctx.selectedWorkPhase.work_phase.start_date,
"day"
);
return dayjs(ctx.selectedWorkPhase.work_phase.start_date).add(
diff,
"day"
);
}
return dayjs(new Date());
}, [ctx.selectedWorkPhase]);

const methods = useForm({
resolver: yupResolver(schema),
Expand Down

0 comments on commit fb57608

Please sign in to comment.