Skip to content

Commit 9477194

Browse files
authored
Make the job report consistent with the existing feature (#2514)
Make the job report consistent with the existing feature: - remove the "sent by" and "sent by email" column - add the row number - sort by created_at ascending
1 parent 7e0c715 commit 9477194

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

app/report/utils.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"Sent by": "Envoyé par",
1818
"Sent by email": "Envoyé par courriel",
1919
"Job": "Tâche",
20+
"Row number": "Numéro de ligne",
2021
"Status": "État",
2122
"Sent Time": "Heure d’envoi",
2223
# notification types
@@ -96,6 +97,7 @@ def build_notifications_query(service_id, notification_type, language, notificat
9697
u.name.label("user_name"),
9798
u.email_address.label("user_email"),
9899
j.original_file_name.label("job_name"),
100+
n.job_row_number.label("job_row_number"),
99101
n.status.label("status"),
100102
n.created_at.label("created_at"),
101103
n.feedback_subtype.label("feedback_subtype"),
@@ -105,7 +107,7 @@ def build_notifications_query(service_id, notification_type, language, notificat
105107
.outerjoin(j, j.id == n.job_id)
106108
.outerjoin(u, u.id == n.created_by_id)
107109
.filter(*query_filters)
108-
.order_by(n.created_at.desc())
110+
.order_by(n.created_at.asc() if job_id else n.created_at.desc())
109111
.subquery()
110112
)
111113

@@ -151,20 +153,38 @@ def build_notifications_query(service_id, notification_type, language, notificat
151153
else_=inner_query.c.notification_type,
152154
).label(translate("Type"))
153155

154-
return db.session.query(
156+
# Create a list of columns for the outer query
157+
query_columns = [
155158
inner_query.c.to.label(translate("Recipient")),
156159
inner_query.c.template_name.label(translate("Template")),
157160
notification_type_translated,
158-
func.coalesce(inner_query.c.user_name, "").label(translate("Sent by")),
159-
func.coalesce(inner_query.c.user_email, "").label(translate("Sent by email")),
160-
func.coalesce(inner_query.c.job_name, "").label(translate("Job")),
161-
status_expr,
162-
# Explicitly cast created_at to UTC, then to America/Toronto
163-
func.to_char(
164-
func.timezone("America/Toronto", func.timezone("UTC", inner_query.c.created_at)), "YYYY-MM-DD HH24:MI:SS"
165-
).label(translate("Sent Time")),
161+
]
162+
163+
# Only include "Sent by" and "Sent by email" columns if job_id is None
164+
if job_id is None:
165+
query_columns.extend(
166+
[
167+
func.coalesce(inner_query.c.user_name, "").label(translate("Sent by")),
168+
func.coalesce(inner_query.c.user_email, "").label(translate("Sent by email")),
169+
]
170+
)
171+
else:
172+
query_columns.insert(0, (inner_query.c.job_row_number + 1).label(translate("Row number")))
173+
174+
# Add the remaining columns
175+
query_columns.extend(
176+
[
177+
func.coalesce(inner_query.c.job_name, "").label(translate("Job")),
178+
status_expr,
179+
# Explicitly cast created_at to UTC, then to America/Toronto
180+
func.to_char(
181+
func.timezone("America/Toronto", func.timezone("UTC", inner_query.c.created_at)), "YYYY-MM-DD HH24:MI:SS"
182+
).label(translate("Sent Time")),
183+
]
166184
)
167185

186+
return db.session.query(*query_columns)
187+
168188

169189
def compile_query_for_copy(query):
170190
"""

0 commit comments

Comments
 (0)