Skip to content

Commit 5676774

Browse files
authored
[Track-332] Keep Minister's Decision in report (#2494)
1 parent 2ca8e15 commit 5676774

File tree

1 file changed

+56
-43
lines changed

1 file changed

+56
-43
lines changed

epictrack-api/src/api/reports/thirty_sixty_ninety_report.py

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from reportlab.lib.enums import TA_CENTER
1313
from reportlab.lib.pagesizes import A4
1414
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
15+
from reportlab.lib.units import inch
1516
from reportlab.pdfbase import pdfmetrics
1617
from reportlab.pdfbase.ttfonts import TTFont
1718
from reportlab.platypus import NextPageTemplate, Paragraph, Table, TableStyle
@@ -332,7 +333,8 @@ def generate_report(
332333

333334
data, styles = self._get_table_data_and_styles(data, normal_style, subheading_style)
334335
table_data.extend(data)
335-
table = Table(table_data)
336+
max_column_width = 4 * inch
337+
table = Table(table_data, colWidths=[None, max_column_width])
336338
table.setStyle(
337339
TableStyle(
338340
[
@@ -343,6 +345,7 @@ def generate_report(
343345
("ALIGN", (0, 0), (-1, -1), "LEFT"),
344346
("FONTNAME", (0, 2), (-1, -1), "BCSans"),
345347
("FONTNAME", (0, 0), (-1, 1), "BCSans-Bold"),
348+
("WORDWRAP", (0, 0), (-1, -1)),
346349
]
347350
+ styles
348351
)
@@ -422,52 +425,62 @@ def _get_valid_event_ids(self, start_date, end_date):
422425
.join(EventConfiguration, Event.event_configuration)
423426
.join(Work, Event.work)
424427
.filter(
425-
func.coalesce(Event.actual_date, Event.anticipated_date).between(
426-
start_date.date(), end_date.date()
427-
),
428428
or_(
429-
Event.event_configuration_id.in_(self.decision_configuration_ids), # Decision events
430-
and_( # High profile work with pcp
431-
Work.is_high_priority.is_(True),
432-
EventConfiguration.event_category_id == EventCategoryEnum.PCP.value,
433-
EventConfiguration.event_type_id == EventTypeEnum.COMMENT_PERIOD.value
434-
),
435-
and_( # High profile events
436-
Work.is_high_priority.is_(True),
437-
Event.high_priority.is_(True),
438-
EventConfiguration.event_category_id.not_in([EventCategoryEnum.CALENDAR.value, EventCategoryEnum.FINANCE.value])
439-
),
440-
and_(
441-
Work.work_type_id == 1, # Project Notification
442-
EventConfiguration.event_category_id == EventCategoryEnum.MILESTONE.value,
443-
EventConfiguration.event_type_id == EventTypeEnum.REFERRAL.value,
444-
EventConfiguration.name == "Project Notification Report referred to Decision Maker",
445-
),
446-
and_(
447-
Work.work_type_id == 2, # Minister's Designation
448-
EventConfiguration.event_category_id == EventCategoryEnum.MILESTONE.value,
449-
EventConfiguration.event_type_id == EventTypeEnum.REFERRAL.value,
450-
EventConfiguration.name != "Minister's Designation Report referred to Decision Maker",
451-
),
452429
and_(
453-
Work.work_type_id == 5, # Exemption Order
454-
EventConfiguration.event_category_id == EventCategoryEnum.MILESTONE.value,
455-
EventConfiguration.event_type_id == EventTypeEnum.REFERRAL.value,
456-
EventConfiguration.name != "Exemption Request Package Referred to Minister",
430+
# Keep Minister's decision with no actual date if anticipated date indicates it should have been made
431+
EventConfiguration.event_type_id == EventTypeEnum.MINISTER_DECISION.value,
432+
Event.actual_date.is_(None),
433+
Event.anticipated_date < start_date.date()
457434
),
458435
and_(
459-
Work.work_type_id == 6, # Assessment
460-
EventConfiguration.event_category_id == EventCategoryEnum.MILESTONE.value,
461-
EventConfiguration.event_type_id == EventTypeEnum.REFERRAL.value,
462-
EventConfiguration.name.in_(["EAC Referral Package sent to Ministers", "Termination Package Referred to Minister"])
463-
),
464-
and_(
465-
Work.work_type_id == 7, # Ammendment
466-
EventConfiguration.event_category_id == EventCategoryEnum.MILESTONE.value,
467-
EventConfiguration.event_type_id == EventTypeEnum.REFERRAL.value,
468-
EventConfiguration.name == "Amendment Decision Package Referred to Decision Maker"
469-
),
470-
),
436+
func.coalesce(Event.actual_date, Event.anticipated_date).between(
437+
start_date.date(), end_date.date()
438+
),
439+
or_(
440+
Event.event_configuration_id.in_(self.decision_configuration_ids), # Decision events
441+
and_( # High profile work with pcp
442+
Work.is_high_priority.is_(True),
443+
EventConfiguration.event_category_id == EventCategoryEnum.PCP.value,
444+
EventConfiguration.event_type_id == EventTypeEnum.COMMENT_PERIOD.value
445+
),
446+
and_( # High profile events
447+
Work.is_high_priority.is_(True),
448+
Event.high_priority.is_(True),
449+
EventConfiguration.event_category_id.not_in([EventCategoryEnum.CALENDAR.value, EventCategoryEnum.FINANCE.value])
450+
),
451+
and_(
452+
Work.work_type_id == 1, # Project Notification
453+
EventConfiguration.event_category_id == EventCategoryEnum.MILESTONE.value,
454+
EventConfiguration.event_type_id == EventTypeEnum.REFERRAL.value,
455+
EventConfiguration.name == "Project Notification Report referred to Decision Maker",
456+
),
457+
and_(
458+
Work.work_type_id == 2, # Minister's Designation
459+
EventConfiguration.event_category_id == EventCategoryEnum.MILESTONE.value,
460+
EventConfiguration.event_type_id == EventTypeEnum.REFERRAL.value,
461+
EventConfiguration.name != "Minister's Designation Report referred to Decision Maker",
462+
),
463+
and_(
464+
Work.work_type_id == 5, # Exemption Order
465+
EventConfiguration.event_category_id == EventCategoryEnum.MILESTONE.value,
466+
EventConfiguration.event_type_id == EventTypeEnum.REFERRAL.value,
467+
EventConfiguration.name != "Exemption Request Package Referred to Minister",
468+
),
469+
and_(
470+
Work.work_type_id == 6, # Assessment
471+
EventConfiguration.event_category_id == EventCategoryEnum.MILESTONE.value,
472+
EventConfiguration.event_type_id == EventTypeEnum.REFERRAL.value,
473+
EventConfiguration.name.in_(["EAC Referral Package sent to Ministers", "Termination Package Referred to Minister"])
474+
),
475+
and_(
476+
Work.work_type_id == 7, # Ammendment
477+
EventConfiguration.event_category_id == EventCategoryEnum.MILESTONE.value,
478+
EventConfiguration.event_type_id == EventTypeEnum.REFERRAL.value,
479+
EventConfiguration.name == "Amendment Decision Package Referred to Decision Maker"
480+
),
481+
),
482+
)
483+
)
471484
)
472485
)
473486
return valid_events

0 commit comments

Comments
 (0)