@@ -280,42 +280,17 @@ def _process_events(
280
280
number_of_days_to_be_pushed = cls ._get_number_of_days_to_be_pushed (
281
281
event , event_old , current_work_phase
282
282
)
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
+ )
319
294
320
295
current_event_index = cls .find_event_index (
321
296
all_work_events , event_old if event_old else event , current_work_phase
@@ -385,6 +360,106 @@ def _process_events(
385
360
current_event_index ,
386
361
)
387
362
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
+
388
463
@classmethod
389
464
def event_compare_func (cls , event_x , event_y ):
390
465
"""Compare function for event sort"""
@@ -452,29 +527,6 @@ def _find_event_index_in_array(cls, events: [Event], event_to_find: Event):
452
527
break
453
528
return index
454
529
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
-
478
530
@classmethod
479
531
def _get_number_of_days_to_be_pushed (
480
532
cls , event : Event , event_old : Event , current_work_phase : WorkPhase
0 commit comments