Skip to content

Commit

Permalink
Merge pull request #435 from deardurham/remove_multiple_see_below
Browse files Browse the repository at this point in the history
Petition file no should be the first file no on the petition
  • Loading branch information
georgehelman authored Sep 13, 2023
2 parents 04b450a + 21fec4b commit 4965254
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
23 changes: 11 additions & 12 deletions dear_petition/petition/export/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def get_ordered_offense_records(self):

return qs

def get_first_record(self):
return self.get_ordered_offense_records().first()

def get_most_recent_record(self):
return self.get_ordered_offense_records().last()

Expand Down Expand Up @@ -109,15 +112,9 @@ def map_header(self):
self.data["Superior"] = Checkbox("")

def map_file_no(self):
ciprs_records = models.CIPRSRecord.objects.filter(offenses__offense_records__documents__id=self.petition_document.id).distinct()
if ciprs_records.count() > 1:
self.data["ConsJdgmntFileNum"] = self.MULTIPLE_FILE_NO_MSG
else:
offense_record = self.get_most_recent_record()
if offense_record:
self.data[
"ConsJdgmntFileNum"
] = offense_record.offense.ciprs_record.file_no
first_record = self.get_first_record()
if first_record:
self.data["ConsJdgmntFileNum"] = first_record.offense.ciprs_record.file_no

def map_petitioner(self):
client = self.extra["client"]
Expand Down Expand Up @@ -218,13 +215,15 @@ def build_form_context(self):
self.map_agencies()
self.map_offenses()

def map_file_no(self):
self.data["FileNo"] = self.MULTIPLE_FILE_NO_MSG

def map_header(self):
super().map_header()
self.data["CountyName"] = self.petition_document.county

def map_file_no(self):
first_record = self.get_first_record()
if first_record:
self.data["FileNo"] = first_record.offense.ciprs_record.file_no

def map_petitioner(self):
client = self.extra["client"]
self.data["PetitionerName"] = client.name
Expand Down
7 changes: 4 additions & 3 deletions dear_petition/petition/export/tests/test_cr285.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def attachment(batch, petition, petition_document, offense_record1):
def form(attachment, extra, client):
form_extra = {}
form_extra.update(extra)
form_extra['client'] = client
form_extra["client"] = client
return AOCFormCR285(petition_document=attachment, extra=form_extra)


Expand Down Expand Up @@ -54,15 +54,16 @@ def test_map_header__district(form):
assert form.data["Superior"] == ""


def test_map_petitioner__file_no(form):
def test_map_file_no__filenum(form, offense_record1, attachment):
form.map_file_no()
assert form.data["FileNo"] == form.MULTIPLE_FILE_NO_MSG
assert form.data["FileNo"] == offense_record1.offense.ciprs_record.file_no


#
# Petitioner
#


def test_map_petitioner__name(form, client):
form.map_petitioner()
assert form.data["PetitionerName"] == client.name
Expand Down
18 changes: 18 additions & 0 deletions dear_petition/sendgrid/migrations/0005_alter_email_subject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.13 on 2023-09-11 05:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("sendgrid", "0004_merge_20230103_1758"),
]

operations = [
migrations.AlterField(
model_name="email",
name="subject",
field=models.CharField(blank=True, default="", max_length=4096),
),
]

0 comments on commit 4965254

Please sign in to comment.