Skip to content

Commit 0050aca

Browse files
authored
Merge pull request #522 from dulshen/summary_dob_portal_imports
Populate DOB on record summary from Petitioner Info
2 parents fb11bfb + f0235ba commit 0050aca

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

dear_petition/petition/api/tests/test_batch.py

+27
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
OffenseFactory,
1414
ClientFactory,
1515
OffenseRecordFactory,
16+
UserFactory,
1617
)
1718

1819
pytestmark = pytest.mark.django_db
@@ -77,3 +78,29 @@ def test_adjust_for_new_client_dob():
7778
batch.save()
7879
batch.adjust_for_new_client_dob()
7980
assert offense_record not in batch.underaged_conviction_records()
81+
82+
83+
def test_populate_client_dob_from_batch_dob(api_client):
84+
"""
85+
Tests that when client dob is left empty, it is populated from the batch dob when
86+
batch has an available dob value.
87+
"""
88+
# set up a user that will have access to the batch/client data
89+
user = UserFactory()
90+
api_client.force_authenticate(user=user)
91+
92+
# set dob to use for the batch record and create batch/record
93+
dob = datetime.date(1992, 1, 28)
94+
batch = BatchFactory(user=user, client=None)
95+
CIPRSRecordFactory(batch=batch, dob=dob) # add record with DOB to batch
96+
97+
client = ClientFactory(user=user, dob=None) # add client with no DOB
98+
assert client.dob == None
99+
100+
# use API to assign the client to the batch
101+
data = {"client_id": client.pk}
102+
api_client.post(reverse("api:batch-assign-client-to-batch", args=[batch.pk]), data=data)
103+
104+
# check that client dob updated appropriately during assignment
105+
client.refresh_from_db()
106+
assert client.dob == dob

dear_petition/petition/api/viewsets.py

+3
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,9 @@ def assign_client_to_batch(self, request, pk):
439439
batch = self.get_object()
440440
batch.client = client
441441
batch.save()
442+
if not client.dob and batch.dob:
443+
client.dob = batch.dob
444+
client.save()
442445
batch.adjust_for_new_client_dob()
443446
return Response({"batch_id": batch.pk})
444447

dear_petition/petition/export/documents/records_summary.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def generate_summary(batch):
3131

3232

3333
def generate_context(batch, attorney, client):
34-
dob = batch.dob
34+
dob = client.dob if client.dob else batch.dob
3535
birthday_18th = "None"
3636
birthday_22nd = "None"
3737

dear_petition/petition/export/documents/tests/test_records_summary.py

+62
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,68 @@ def test_records_summary_context__birthdays(
419419
assert context["birthday_22nd"] == formatted_22nd_bday
420420

421421

422+
@pytest.mark.parametrize(
423+
"dob, formatted_dob, formatted_18th_bday, formatted_22nd_bday",
424+
[
425+
(date(1986, 6, 15), "06/15/1986", "06/15/2004", "06/15/2008"),
426+
# born in leap year
427+
(date(1996, 2, 29), "02/29/1996", "03/01/2014", "03/01/2018"),
428+
],
429+
)
430+
def test_records_summary_context_no_batch_birthday(
431+
batch, dob, formatted_dob, formatted_18th_bday, formatted_22nd_bday
432+
):
433+
"""
434+
Test generate_context method for a batch that has no date of birth, but client info has
435+
date of birth, (e.g. for portal imported batches)
436+
"""
437+
438+
PETITIONER_INFO_WITH_DOB = {"name": "Pete Petitioner", "dob": dob}
439+
440+
offense = create_offense(
441+
batch, "DURHAM", DISTRICT_COURT, "10CR000001", None, "NOT GUILTY", "JURY TRIAL", False
442+
)
443+
create_offense_record(offense, CHARGED, "SIMPLE ASSAULT", "MISDEMEANOR")
444+
445+
attorney = AttorneyFactory(name="E. Toruney")
446+
client = ClientFactory(**PETITIONER_INFO_WITH_DOB)
447+
context = generate_context(batch, attorney, client)
448+
449+
assert context["dob"] == formatted_dob
450+
assert context["birthday_18th"] == formatted_18th_bday
451+
assert context["birthday_22nd"] == formatted_22nd_bday
452+
453+
454+
def test_records_summary_context_birthdays_discrepancy(batch):
455+
"""
456+
Test generate_context method where client date of birth does not match batch date of birth.
457+
Client date of birth should be used in this case.
458+
"""
459+
460+
client_dob, formatted_dob, formatted_18th_bday, formatted_22nd_bday = (
461+
date(1986, 6, 15),
462+
"06/15/1986",
463+
"06/15/2004",
464+
"06/15/2008",
465+
)
466+
batch_dob = date(1993, 5, 22)
467+
468+
PETITIONER_INFO_WITH_DOB = {"name": "Pete Petitioner", "dob": client_dob}
469+
470+
offense = create_offense(
471+
batch, "DURHAM", DISTRICT_COURT, "10CR000001", batch_dob, "NOT GUILTY", "JURY TRIAL", False
472+
)
473+
create_offense_record(offense, CHARGED, "SIMPLE ASSAULT", "MISDEMEANOR")
474+
475+
attorney = AttorneyFactory(name="E. Toruney")
476+
client = ClientFactory(**PETITIONER_INFO_WITH_DOB)
477+
context = generate_context(batch, attorney, client)
478+
479+
assert context["dob"] == formatted_dob
480+
assert context["birthday_18th"] == formatted_18th_bday
481+
assert context["birthday_22nd"] == formatted_22nd_bday
482+
483+
422484
def test_records_summary_context__additional_offenses(batch):
423485
"""
424486
Test generate_context method with many offense records in a table. Check that addl_offense_file_nos in the table has

0 commit comments

Comments
 (0)