From 979c95b41a8190d03a3183900c076b0b76b85920 Mon Sep 17 00:00:00 2001 From: George Helman Date: Sat, 23 Mar 2024 18:09:14 -0400 Subject: [PATCH] District court offenses were showing up on the superior court petitions because the filter condition was using the jurisdiction fo the CIPRS record rather than the jurisdiction of the record. I suspect this is an artifact of the time when we thought a CIPRS record had only one jurisdiction. We now know that it is possible for a CIPRS record to have both in the case of superseding indictments. The convictions petitions should go by the jurisdiction of the offense, rather than the CIPRS record --- dear_petition/petition/types/dismissed.py | 2 +- dear_petition/petition/types/main.py | 4 ++-- dear_petition/petition/types/not_guilty.py | 2 +- dear_petition/petition/types/tests/test_dismissed.py | 1 + dear_petition/petition/types/underaged_convictions.py | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/dear_petition/petition/types/dismissed.py b/dear_petition/petition/types/dismissed.py index 3dfbdacb..c60f5b64 100644 --- a/dear_petition/petition/types/dismissed.py +++ b/dear_petition/petition/types/dismissed.py @@ -7,7 +7,7 @@ def get_offense_records(batch, jurisdiction=""): qs = OffenseRecord.objects.filter(offense__ciprs_record__batch=batch) if jurisdiction: - qs = qs.filter(offense__ciprs_record__jurisdiction=jurisdiction) + qs = qs.filter(offense__jurisdiction=jurisdiction) qs = qs.filter(build_query()).exclude(severity="INFRACTION") return qs.select_related("offense__ciprs_record__batch") diff --git a/dear_petition/petition/types/main.py b/dear_petition/petition/types/main.py index eaf23485..9a433ff9 100644 --- a/dear_petition/petition/types/main.py +++ b/dear_petition/petition/types/main.py @@ -30,10 +30,10 @@ def petition_offense_records(batch, petition_type, jurisdiction=""): def identify_distinct_petitions(offense_records): qs = offense_records.values( - "offense__ciprs_record__jurisdiction", "offense__ciprs_record__county" + "offense__jurisdiction", "offense__ciprs_record__county" ) qs = qs.values( - jurisdiction=F("offense__ciprs_record__jurisdiction"), + jurisdiction=F("offense__jurisdiction"), county=F("offense__ciprs_record__county"), ).distinct() logger.info(f"Distinct petitions: {list(qs.values_list('county', 'jurisdiction'))}") diff --git a/dear_petition/petition/types/not_guilty.py b/dear_petition/petition/types/not_guilty.py index 1106d33d..1a1902ec 100644 --- a/dear_petition/petition/types/not_guilty.py +++ b/dear_petition/petition/types/not_guilty.py @@ -7,7 +7,7 @@ def get_offense_records(batch, jurisdiction=""): qs = OffenseRecord.objects.filter(offense__ciprs_record__batch=batch) if jurisdiction: - qs = qs.filter(offense__ciprs_record__jurisdiction=jurisdiction) + qs = qs.filter(offense__jurisdiction=jurisdiction) query = build_query() qs = qs.filter(query).exclude(severity="INFRACTION") return qs.select_related("offense__ciprs_record__batch") diff --git a/dear_petition/petition/types/tests/test_dismissed.py b/dear_petition/petition/types/tests/test_dismissed.py index ba8ba86f..a6f240dc 100644 --- a/dear_petition/petition/types/tests/test_dismissed.py +++ b/dear_petition/petition/types/tests/test_dismissed.py @@ -54,6 +54,7 @@ def test_offense_records_by_jurisdiction(batch, jurisdiction): offense = OffenseFactory( disposition_method=constants.DISMISSED_DISPOSITION_METHODS[0], ciprs_record=ciprs_record, + jurisdiction=jurisdiction, ) offense_record = OffenseRecordFactory(action="CHARGED", offense=offense) records = batch.dismissed_offense_records(jurisdiction=jurisdiction) diff --git a/dear_petition/petition/types/underaged_convictions.py b/dear_petition/petition/types/underaged_convictions.py index fbfcb015..54dfc3fa 100644 --- a/dear_petition/petition/types/underaged_convictions.py +++ b/dear_petition/petition/types/underaged_convictions.py @@ -25,7 +25,7 @@ def get_offense_records(batch, jurisdiction=""): return qs # We can't determine this petition type without the date of birth if jurisdiction: - qs = qs.filter(offense__ciprs_record__jurisdiction=jurisdiction) + qs = qs.filter(offense__jurisdiction=jurisdiction) query = build_query(dob) qs = qs.filter(query).exclude(severity="INFRACTION")