1
1
"""Disable work start date action handler"""
2
2
3
- from datetime import timedelta
4
-
5
3
from api .actions .base import ActionFactory
6
4
from api .models import Event , db
7
5
from api .models .event_configuration import EventConfiguration
8
6
from api .models .event_template import EventTemplateVisibilityEnum
9
7
from api .models .phase_code import PhaseCode
10
8
from api .models .work_phase import WorkPhase
11
- from api .schemas .response .event_configuration_response import EventConfigurationResponseSchema
9
+ from api .schemas .response .event_configuration_response import (
10
+ EventConfigurationResponseSchema ,
11
+ )
12
12
from api .schemas .response .event_template_response import EventTemplateResponseSchema
13
+ from .set_event_date import SetEventDate
14
+ from .common import find_event_date
13
15
14
16
15
17
# pylint: disable=import-outside-toplevel
@@ -21,18 +23,23 @@ class AddEvent(ActionFactory):
21
23
def run (self , source_event : Event , params ) -> None :
22
24
"""Adds a new event based on params"""
23
25
from api .services .event import EventService
24
-
25
- event_data , work_phase_id = self .get_additional_params (source_event , params )
26
- event_data .update (
27
- {
28
- "is_active" : True ,
29
- "work_id" : source_event .work_id ,
30
- "anticipated_date" : source_event .actual_date + timedelta (days = params ["start_at" ]),
31
- }
32
- )
33
- EventService .create_event (
34
- event_data , work_phase_id = work_phase_id , push_events = True
35
- )
26
+ for param in params :
27
+ event_data , work_phase_id = self .get_additional_params (source_event , param )
28
+ event_data .update (
29
+ {
30
+ "is_active" : True ,
31
+ "work_id" : source_event .work_id ,
32
+ "anticipated_date" : find_event_date (source_event )
33
+ }
34
+ )
35
+ new_event = EventService .create_event (
36
+ event_data , work_phase_id = work_phase_id , push_events = True , commit = False
37
+ )
38
+ set_event_date : SetEventDate = SetEventDate ()
39
+ # param["event_name"] = new_event.event_configuration.name
40
+ # Setting the event date from here cz, otherwise the event won't get pushed
41
+ set_event_date .run (source_event , param )
42
+ source_event = new_event
36
43
37
44
def get_additional_params (self , source_event : Event , params ):
38
45
"""Returns additional parameter"""
@@ -56,7 +63,7 @@ def get_additional_params(self, source_event: Event, params):
56
63
db .session .query (EventConfiguration )
57
64
.filter (
58
65
EventConfiguration .work_phase_id == work_phase .id ,
59
- EventConfiguration .name == params .pop ("event_name" ),
66
+ EventConfiguration .name == params .get ("event_name" ),
60
67
EventConfiguration .is_active .is_ (True ),
61
68
)
62
69
.order_by (EventConfiguration .repeat_count .desc ())
0 commit comments