Skip to content

Commit a5a0937

Browse files
authored
Merge pull request #5614 from raft-tech/5599-email-template-updates
Update Submission Email Templates
2 parents 33ed6c8 + 27394a3 commit a5a0937

File tree

12 files changed

+184
-84
lines changed

12 files changed

+184
-84
lines changed

tdrs-backend/tdpservice/email/helpers/data_file.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ def get_tanf_aggregates_context_count(datafile_summary):
6363
}
6464

6565

66+
def get_tanf_total_errors_context_count(datafile_summary):
67+
"""Return the sum of total errors across all months for aggregate/stratum TANF files."""
68+
case_aggregates = datafile_summary.case_aggregates or {}
69+
total_errors = 0
70+
71+
if "months" in case_aggregates:
72+
for month in case_aggregates["months"]:
73+
total_errors += (
74+
month["total_errors"]
75+
if "total_errors" in month and month["total_errors"] != "N/A"
76+
else 0
77+
)
78+
79+
return {"total_errors": total_errors}
80+
81+
6682
def get_fra_aggregates_context_count(datafile_summary):
6783
"""Return the relevant context data from case aggregates for FRA files."""
6884
case_aggregates = datafile_summary.case_aggregates or {}
@@ -104,6 +120,11 @@ def send_data_submitted_email(
104120
fiscal_year = datafile.fiscal_year
105121
submitted_by = datafile.submitted_by
106122

123+
is_aggregate = datafile.section in (
124+
DataFile.Section.AGGREGATE_DATA,
125+
DataFile.Section.STRATUM_DATA,
126+
)
127+
107128
context = {
108129
"stt_name": stt_name,
109130
"submission_date": submission_date,
@@ -113,6 +134,7 @@ def send_data_submitted_email(
113134
"file_type": file_type,
114135
"status": datafile_summary.status,
115136
"has_errors": datafile_summary.status != DataFileSummary.Status.ACCEPTED,
137+
"is_aggregate": is_aggregate,
116138
"url": settings.FRONTEND_BASE_URL,
117139
}
118140

@@ -133,7 +155,10 @@ def send_data_submitted_email(
133155
| DataFile.ProgramType.SSP
134156
| DataFile.ProgramType.TRIBAL
135157
):
136-
context.update(get_tanf_aggregates_context_count(datafile_summary))
158+
if is_aggregate:
159+
context.update(get_tanf_total_errors_context_count(datafile_summary))
160+
else:
161+
context.update(get_tanf_aggregates_context_count(datafile_summary))
137162

138163
template_options = {
139164
DataFileSummary.Status.ACCEPTED: TanfDataFileEmail.ACCEPTED.value,

tdrs-backend/tdpservice/email/helpers/test/test_data_file.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from tdpservice.data_files.models import DataFile
88
from tdpservice.email.helpers.data_file import (
9+
get_tanf_aggregates_context_count,
10+
get_tanf_total_errors_context_count,
911
send_data_submitted_email,
1012
send_stuck_file_email,
1113
)
@@ -200,6 +202,120 @@ def test_send_data_submitted_email(
200202
assert mail.outbox[0].body == msg
201203

202204

205+
class TestGetTanfAggregatesContextCount:
206+
"""Tests for get_tanf_aggregates_context_count."""
207+
208+
def test_with_case_data(self):
209+
"""Test aggregation with typical case data months."""
210+
dfs = DataFileSummary()
211+
dfs.case_aggregates = {
212+
"months": [
213+
{
214+
"month": "Jan",
215+
"accepted_without_errors": 10,
216+
"accepted_with_errors": 2,
217+
},
218+
{
219+
"month": "Feb",
220+
"accepted_without_errors": 8,
221+
"accepted_with_errors": 3,
222+
},
223+
{
224+
"month": "Mar",
225+
"accepted_without_errors": 12,
226+
"accepted_with_errors": 1,
227+
},
228+
],
229+
"rejected": 5,
230+
}
231+
result = get_tanf_aggregates_context_count(dfs)
232+
assert result == {
233+
"cases_without_errors": 30,
234+
"cases_with_errors": 6,
235+
"records_unable_to_process": 5,
236+
}
237+
238+
def test_with_na_values(self):
239+
"""Test aggregation handles N/A values from rejected status."""
240+
dfs = DataFileSummary()
241+
dfs.case_aggregates = {
242+
"months": [
243+
{
244+
"month": "Jan",
245+
"accepted_without_errors": "N/A",
246+
"accepted_with_errors": "N/A",
247+
},
248+
],
249+
"rejected": 0,
250+
}
251+
result = get_tanf_aggregates_context_count(dfs)
252+
assert result == {
253+
"cases_without_errors": 0,
254+
"cases_with_errors": 0,
255+
"records_unable_to_process": 0,
256+
}
257+
258+
def test_with_empty_aggregates(self):
259+
"""Test aggregation handles empty/None case_aggregates."""
260+
dfs = DataFileSummary()
261+
dfs.case_aggregates = None
262+
result = get_tanf_aggregates_context_count(dfs)
263+
assert result == {
264+
"cases_without_errors": 0,
265+
"cases_with_errors": 0,
266+
"records_unable_to_process": 0,
267+
}
268+
269+
270+
class TestGetTanfTotalErrorsContextCount:
271+
"""Tests for get_tanf_total_errors_context_count."""
272+
273+
def test_with_total_errors_data(self):
274+
"""Test aggregation sums total_errors across months."""
275+
dfs = DataFileSummary()
276+
dfs.case_aggregates = {
277+
"months": [
278+
{"month": "Jan", "total_errors": 5},
279+
{"month": "Feb", "total_errors": 3},
280+
{"month": "Mar", "total_errors": 7},
281+
],
282+
}
283+
result = get_tanf_total_errors_context_count(dfs)
284+
assert result == {"total_errors": 15}
285+
286+
def test_with_na_values(self):
287+
"""Test aggregation handles N/A values from rejected status."""
288+
dfs = DataFileSummary()
289+
dfs.case_aggregates = {
290+
"months": [
291+
{"month": "Jan", "total_errors": "N/A"},
292+
{"month": "Feb", "total_errors": "N/A"},
293+
],
294+
}
295+
result = get_tanf_total_errors_context_count(dfs)
296+
assert result == {"total_errors": 0}
297+
298+
def test_with_empty_aggregates(self):
299+
"""Test aggregation handles empty/None case_aggregates."""
300+
dfs = DataFileSummary()
301+
dfs.case_aggregates = None
302+
result = get_tanf_total_errors_context_count(dfs)
303+
assert result == {"total_errors": 0}
304+
305+
def test_with_mixed_values(self):
306+
"""Test aggregation handles mix of numeric and N/A values."""
307+
dfs = DataFileSummary()
308+
dfs.case_aggregates = {
309+
"months": [
310+
{"month": "Jan", "total_errors": 5},
311+
{"month": "Feb", "total_errors": "N/A"},
312+
{"month": "Mar", "total_errors": 10},
313+
],
314+
}
315+
result = get_tanf_total_errors_context_count(dfs)
316+
assert result == {"total_errors": 15}
317+
318+
203319
@pytest.mark.django_db
204320
def test_send_stuck_file_email(user, stt):
205321
"""Test that the send_stuck_file_email function runs."""

tdrs-backend/tdpservice/email/templates/datafile_base.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@
4747
<p>
4848
{% block end_message %}
4949
{% endblock %}
50+
{% if file_type == "FRA" %}
51+
<a href="https://tdp-project-updates.app.cloud.gov/knowledge-center/submitting-fra-data.html#:~:text=your%20previous%20submission.-,Viewing,-FRA%20Submission%20History" target="_blank">
52+
Read more about using Submission History
53+
</a>
54+
{% else %}
5055
<a href="https://tdp-project-updates.app.cloud.gov/knowledge-center/view-submission-history.html" target="_blank">
5156
Read more about using Submission History
5257
</a>
58+
{% endif %}
5359
</p>
5460

5561
<p>

tdrs-backend/tdpservice/email/templates/fra-data-submitted.html

Lines changed: 0 additions & 71 deletions
This file was deleted.

tdrs-backend/tdpservice/email/templates/fra/accepted.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends '../datafile_base.html' %}
22

33
{% block message %}
4-
Your <b>{{ file_type }}</b> data files submitted by <b>{{ stt_name }}</b> on <b>{{ submission_date }}</b> in Fiscal Year <b>{{ fiscal_year }}</b> have been processed and accepted.
4+
Your <b>{{ file_type }}</b> data files submitted for <b>{{ stt_name }}</b> on <b>{{ submission_date }}</b> in Fiscal Year <b>{{ fiscal_year }}</b> have been processed and accepted.
55
{% endblock %}
66

77
{% block table %}
@@ -29,5 +29,5 @@
2929
{% endblock %}
3030

3131
{% block end_message %}
32-
The data file can now be accessed via the Submission History tab of the Data Files page.
32+
The data file can now be accessed on the FRA Data Files page.
3333
{% endblock %}

tdrs-backend/tdpservice/email/templates/fra/accepted_with_errors.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends '../datafile_base.html' %}
22

33
{% block message %}
4-
Your <b>{{ file_type }}</b> data files submitted by <b>{{ stt_name }}</b> on <b>{{ submission_date }}</b> in Fiscal Year <b>{{ fiscal_year }}</b> have been processed, but <b>some cases within your data contain errors</b>. Review the error report(s) for more details, and <b>resubmit your data files</b> once the errors have been corrected.
4+
Your <b>{{ file_type }}</b> data files submitted for <b>{{ stt_name }}</b> on <b>{{ submission_date }}</b> in Fiscal Year <b>{{ fiscal_year }}</b> have been processed, but <b>some cases within your data contain errors</b>. Review the error report(s) for more details, and <b>resubmit your data files</b> once the errors have been corrected.
55
{% endblock %}
66

77
{% block table %}
@@ -39,5 +39,5 @@
3939
{% endblock %}
4040

4141
{% block end_message %}
42-
The data file and the error report can now be accessed via the Submission History tab of the Data Files page.
42+
The data file and the error report can now be accessed on the FRA Data Files page.
4343
{% endblock %}

tdrs-backend/tdpservice/email/templates/fra/partially_accepted.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends '../datafile_base.html' %}
22

33
{% block message %}
4-
Your <b>{{ file_type }}</b> data files submitted by <b>{{ stt_name }}</b> on <b>{{ submission_date }}</b> in Fiscal Year <b>{{ fiscal_year }}</b> were <b>unable to be processed</b>. Review the error report(s) for more details, and <b>resubmit your data files</b> once the errors have been corrected.
4+
Your <b>{{ file_type }}</b> data files submitted for <b>{{ stt_name }}</b> on <b>{{ submission_date }}</b> in Fiscal Year <b>{{ fiscal_year }}</b> were <b>unable to be fully processed</b>. Review the error report(s) for more details, and <b>resubmit your data files</b> once the errors have been corrected.
55
{% endblock %}
66

77
{% block table %}
@@ -39,5 +39,5 @@
3939
{% endblock %}
4040

4141
{% block end_message %}
42-
The data file and the error report(s) can now be accessed via the Submission History tab of the Data Files page.
42+
The data file and the error report(s) can now be accessed on the FRA Data Files page.
4343
{% endblock %}

tdrs-backend/tdpservice/email/templates/fra/rejected.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends '../datafile_base.html' %}
22

33
{% block message %}
4-
Your <b>{{ file_type }}</b> data files submitted by <b>{{ stt_name }}</b> on <b>{{ submission_date }}</b> in Fiscal Year <b>{{ fiscal_year }}</b> were <b>unable to be processed</b>. Review the error report(s) for more details, and <b>resubmit your data files</b> once the errors have been corrected.
4+
Your <b>{{ file_type }}</b> data files submitted for <b>{{ stt_name }}</b> on <b>{{ submission_date }}</b> in Fiscal Year <b>{{ fiscal_year }}</b> were <b>unable to be processed</b>. Review the error report(s) for more details, and <b>resubmit your data files</b> once the errors have been corrected.
55
{% endblock %}
66

77
{% block table %}
@@ -39,5 +39,5 @@
3939
{% endblock %}
4040

4141
{% block end_message %}
42-
The data file and the error report(s) can now be accessed via the Submission History tab of the Data Files page.
42+
The data file and the error report(s) can now be accessed on the FRA Data Files page.
4343
{% endblock %}

tdrs-backend/tdpservice/email/templates/tanf/accepted.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% extends '../datafile_base.html' %}
22

33
{% block message %}
4-
Your <b>{{ file_type }}</b> data files submitted by <b>{{ stt_name }}</b> on <b>{{ submission_date }}</b> in Fiscal Year <b>{{ fiscal_year }}</b> have been processed and accepted.
4+
Your <b>{{ file_type }}</b> data files submitted for <b>{{ stt_name }}</b> on <b>{{ submission_date }}</b> in Fiscal Year <b>{{ fiscal_year }}</b> have been processed and accepted.
55
{% endblock %}
66

77
{% block table %}
@@ -14,15 +14,23 @@
1414
<th>Section</th>
1515
<th>Submitted By</th>
1616
<th>Status</th>
17+
{% if is_aggregate %}
18+
<th>Total Errors</th>
19+
{% else %}
1720
<th>Cases Without Errors</th>
21+
{% endif %}
1822
</tr>
1923
</thead>
2024
<tbody>
2125
<tr>
2226
<td>{{ section_name }}</td>
2327
<td>{{ submitted_by }}</td>
2428
<td>{{ status }}</td>
29+
{% if is_aggregate %}
30+
<td>{{ total_errors }}</td>
31+
{% else %}
2532
<td>{{ cases_without_errors }}</td>
33+
{% endif %}
2634
</tr>
2735
</tbody>
2836
</table>

0 commit comments

Comments
 (0)