3
3
4
4
from flask import jsonify , current_app
5
5
from pytz import timezone
6
- from sqlalchemy import and_ , func , select
6
+ from sqlalchemy import and_ , func , select , or_
7
7
from sqlalchemy .dialects .postgresql import INTERVAL
8
8
from sqlalchemy .orm import aliased
9
9
@@ -39,6 +39,7 @@ class EAAnticipatedScheduleReport(ReportFactory):
39
39
def __init__ (self , filters , color_intensity ):
40
40
"""Initialize the ReportFactory"""
41
41
data_keys = [
42
+ "work_id" ,
42
43
"phase_name" ,
43
44
"date_updated" ,
44
45
"project_name" ,
@@ -59,6 +60,8 @@ def __init__(self, filters, color_intensity):
59
60
"next_pecp_title" ,
60
61
"next_pecp_short_description" ,
61
62
"milestone_type" ,
63
+ "category_type" ,
64
+ "event_name"
62
65
]
63
66
group_by = "phase_name"
64
67
template_name = "anticipated_schedule.docx"
@@ -79,6 +82,8 @@ def _fetch_data(self, report_date):
79
82
exclude_phase_names = []
80
83
if self .filters and "exclude" in self .filters :
81
84
exclude_phase_names = self .filters ["exclude" ]
85
+
86
+ current_app .logger .debug (f"Executing query for { self .report_title } report" )
82
87
results_qry = (
83
88
db .session .query (Work )
84
89
.join (Event , Event .work_id == Work .id )
@@ -122,15 +127,71 @@ def _fetch_data(self, report_date):
122
127
)
123
128
# FILTER ENTRIES MATCHING MIN DATE FOR NEXT PECP OR NO WORK ENGAGEMENTS (FOR AMENDMENTS)
124
129
.filter (
125
- Work .is_active .is_ (True ),
126
- Work .is_deleted .is_ (False ),
127
- Work .work_state .in_ (
128
- [WorkStateEnum .IN_PROGRESS .value , WorkStateEnum .SUSPENDED .value ]
129
- ),
130
- # Filter out specific WorkPhase names
131
- ~ WorkPhase .name .in_ (exclude_phase_names )
130
+ Work .is_active .is_ (True ),
131
+ Event .anticipated_date .between (report_date - timedelta (days = 7 ), report_date + timedelta (days = 366 )),
132
+ or_ (
133
+ Event .event_configuration_id .in_ (
134
+ db .session .query (EventConfiguration .id ).filter (
135
+ EventConfiguration .event_type_id == 5 , # EA Referral
136
+ EventConfiguration .event_category_id == 1 # Milestone,
137
+ )
138
+ ),
139
+ Event .event_configuration_id .in_ (
140
+ db .session .query (EventConfiguration .id ).filter (
141
+ EventConfiguration .event_category_id == 4 , # Decision
142
+ EventConfiguration .event_type_id == 14 # Minister
143
+ )
144
+ ),
145
+ Event .event_configuration_id .in_ (
146
+ db .session .query (EventConfiguration .id ).filter (
147
+ EventConfiguration .event_category_id == 4 , # Decision
148
+ EventConfiguration .name != "IPD/EP Approval Decision (Day Zero)" ,
149
+ EventConfiguration .event_type_id == 15 # CEAO
150
+ )
151
+ ),
152
+ Event .event_configuration_id .in_ (
153
+ db .session .query (EventConfiguration .id ).filter (
154
+ EventConfiguration .event_category_id == 4 , # Decision
155
+ EventConfiguration .name != "IPD/EP Approval Decision (Day Zero)" ,
156
+ EventConfiguration .name != "Revised EAC Application Acceptance Decision (Day Zero)" ,
157
+ EventConfiguration .event_type_id == 15 # CEAO
158
+ )
159
+ ),
160
+ Event .event_configuration_id .in_ (
161
+ db .session .query (EventConfiguration .id ).filter (
162
+ EventConfiguration .event_category_id == 4 , # Decision
163
+ EventConfiguration .name != "Delegation of Amendment Decision" ,
164
+ or_ (
165
+ EventConfiguration .event_type_id == 15 , # CEAO
166
+ EventConfiguration .event_type_id == 16 # ADM
167
+ )
168
+ )
169
+ ),
170
+ Event .event_configuration_id .in_ (
171
+ db .session .query (EventConfiguration .id ).filter (
172
+ EventConfiguration .event_category_id == 4 , # Decision
173
+ EventConfiguration .name != "Delegation of SubStart Decision to Minister" ,
174
+ EventConfiguration .event_type_id == 15 # CEAO
175
+ )
176
+ ),
177
+ Event .event_configuration_id .in_ (
178
+ db .session .query (EventConfiguration .id ).filter (
179
+ EventConfiguration .event_category_id == 4 , # Decision
180
+ EventConfiguration .name != "Delegation of Transfer Decision to Minister" ,
181
+ or_ (
182
+ EventConfiguration .event_type_id == 15 , # CEAO
183
+ EventConfiguration .event_type_id == 16 # ADM
184
+ )
185
+ )
186
+ )
187
+ ),
188
+ Work .is_deleted .is_ (False ),
189
+ Work .work_state .in_ ([WorkStateEnum .IN_PROGRESS .value , WorkStateEnum .SUSPENDED .value ]),
190
+ # Filter out specific WorkPhase names
191
+ ~ WorkPhase .name .in_ (exclude_phase_names )
132
192
)
133
193
.add_columns (
194
+ Work .id .label ("work_id" ),
134
195
PhaseCode .name .label ("phase_name" ),
135
196
latest_status_updates .c .posted_date .label ("date_updated" ),
136
197
Project .name .label ("project_name" ),
@@ -154,6 +215,8 @@ def _fetch_data(self, report_date):
154
215
eac_decision_by .full_name .label ("eac_decision_by" ),
155
216
decision_by .full_name .label ("decision_by" ),
156
217
EventConfiguration .event_type_id .label ("milestone_type" ),
218
+ EventConfiguration .event_category_id .label ("category_type" ),
219
+ EventConfiguration .name .label ("event_name" ),
157
220
func .coalesce (next_pecp_query .c .name , Event .name ).label (
158
221
"next_pecp_title"
159
222
),
0 commit comments