Skip to content

Commit 9c42f10

Browse files
authored
Merge pull request #1806 from wittejm/jw/compiled-fines-waiver
compiled fees
2 parents 261d08a + fa26d1a commit 9c42f10

File tree

3 files changed

+25
-47
lines changed

3 files changed

+25
-47
lines changed

src/backend/expungeservice/form_filling.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -648,32 +648,11 @@ def build_zip(record_summary: RecordSummary, user_information_dict: Dict[str, st
648648
osp_file_info = FormFilling._create_and_write_pdf(user_information_dict_2, temp_dir)
649649
zip_file.write(*osp_file_info[0:2])
650650

651-
#todo: refactor and build separate method to compose compiled
652651
if all_motions_to_set_aside:
653-
compiled = PdfWriter()
654-
655-
# Must rename all the fields in the file so they are unique so that Acrobat doesn't mess with their values.
656-
reader = PdfReader(all_motions_to_set_aside.pop(0)[0])
657-
start_index = 0
658-
field_count = FormFilling.rename_fields(reader, start_index)
659-
start_index += field_count
660-
compiled.addpages(reader.pages)
661-
for f in all_motions_to_set_aside:
662-
reader = PdfReader(f[0])
663-
field_count = FormFilling.rename_fields(reader, start_index)
664-
start_index += field_count
665-
compiled.addpages(reader.pages)
666-
667-
reader = PdfReader(osp_file_info[0])
668-
FormFilling.rename_fields(reader, start_index)
669-
compiled.addpages(reader.pages)
670-
671-
# Must update the appearances property so that the fields render correctly in Acrobat.
672-
compiled.trailer.Root.AcroForm = PdfDict(NeedAppearances=PdfObject("true"))
673-
652+
file_paths = [f[0] for f in all_motions_to_set_aside] + [osp_file_info[0]]
674653
comp_name = "COMPILED.pdf"
675654
comp_path = path.join(temp_dir, comp_name)
676-
compiled.write(comp_path)
655+
FormFilling.compile_pdfs(file_paths, comp_path)
677656
zip_file.write(comp_path, comp_name)
678657

679658

@@ -697,6 +676,18 @@ def rename_fields(reader: PdfReader, start_index: int) -> int:
697676
field[PdfName('T')] = new_name
698677
return len(fields)
699678

679+
@staticmethod
680+
def compile_pdfs(file_paths: List[str], output_path: str) -> None:
681+
compiled = PdfWriter()
682+
start_index = 0
683+
for file_path in file_paths:
684+
reader = PdfReader(file_path)
685+
field_count = FormFilling.rename_fields(reader, start_index)
686+
start_index += field_count
687+
compiled.addpages(reader.pages)
688+
compiled.trailer.Root.AcroForm = PdfDict(NeedAppearances=PdfObject("true"))
689+
compiled.write(output_path)
690+
700691
@staticmethod
701692
def build_summary_filename(aliases):
702693
first_alias = aliases[0]

src/backend/expungeservice/form_filling_2026.py

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
from typing import Any, Dict, List, Optional, Tuple
1818
from zipfile import ZipFile
1919

20-
from pdfrw import PdfReader, PdfWriter, PdfDict, PdfObject
21-
2220
from expungeservice.form_filling import (
2321
CaseResults,
2422
DA_ADDRESSES,
@@ -325,29 +323,10 @@ def build_zip(
325323

326324
# Build compiled PDF
327325
if all_motions_to_set_aside:
328-
compiled = PdfWriter()
329-
330-
# Must rename all the fields in the file so they are unique so that Acrobat doesn't mess with their values.
331-
reader = PdfReader(all_motions_to_set_aside.pop(0)[0])
332-
start_index = 0
333-
field_count = OldFormFilling.rename_fields(reader, start_index)
334-
start_index += field_count
335-
compiled.addpages(reader.pages)
336-
for f in all_motions_to_set_aside:
337-
reader = PdfReader(f[0])
338-
field_count = OldFormFilling.rename_fields(reader, start_index)
339-
start_index += field_count
340-
compiled.addpages(reader.pages)
341-
342-
reader = PdfReader(osp_file_info[0])
343-
OldFormFilling.rename_fields(reader, start_index)
344-
compiled.addpages(reader.pages)
345-
346-
compiled.trailer.Root.AcroForm = PdfDict(NeedAppearances=PdfObject("true"))
347-
326+
file_paths = [f[0] for f in all_motions_to_set_aside] + [osp_file_info[0]]
348327
comp_name = "COMPILED.pdf"
349328
comp_path = path.join(temp_dir, comp_name)
350-
compiled.write(comp_path)
329+
OldFormFilling.compile_pdfs(file_paths, comp_path)
351330
zip_file.write(comp_path, comp_name)
352331

353332
# Add summary PDF

src/backend/expungeservice/waiver_form_filling.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from expungeservice.models.record_summary import RecordSummary
1212
from expungeservice.models.case import Case
13-
from expungeservice.form_filling import DA_ADDRESSES
13+
from expungeservice.form_filling import DA_ADDRESSES, FormFilling
1414

1515
def wrap_text(text):
1616
text = re.sub(r'\r\n?|\n', ' ', text)
@@ -84,6 +84,7 @@ def build_zip(
8484
zip_path = path.join(mkdtemp(), zip_file_name)
8585
zip_file = ZipFile(zip_path, "w")
8686

87+
all_waiver_files = []
8788
for case in record_summary.record.cases:
8889
if (
8990
case.summary.balance_due_in_cents > 0
@@ -92,6 +93,13 @@ def build_zip(
9293
case_data = CaseData(case, user_information_dict, waiver_information_dict)
9394
file_info = WaiverFormFilling._create_and_write_pdf(case_data, temp_dir)
9495
zip_file.write(*file_info[0:2])
96+
all_waiver_files.append(file_info)
97+
98+
if all_waiver_files:
99+
file_paths = [f[0] for f in all_waiver_files]
100+
comp_path = path.join(temp_dir, "COMPILED_FINES_AND_FEES.pdf")
101+
FormFilling.compile_pdfs(file_paths, comp_path)
102+
zip_file.write(comp_path, "COMPILED_FINES_AND_FEES.pdf")
95103

96104
zip_file.close()
97105

0 commit comments

Comments
 (0)