Keep only the latest file of a Document Type in each property's folder 🟩

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-07-08 09:04:58 +00:00
parent 28b7b43372
commit 810e910961

View file

@ -63,4 +63,21 @@ def plan_download_package(
"""Lay out a Download Package from resolved documents (ADR-0060): one folder
per property, the latest file of each Document Type, null-Document-Type rows
skipped and reported."""
raise NotImplementedError
latest_by_group: dict[tuple[str, str], ResolvedDocument] = {}
for document in documents:
assert document.document_type is not None
group = (document.landlord_property_id, document.document_type)
incumbent = latest_by_group.get(group)
if incumbent is None or document.uploaded_at > incumbent.uploaded_at:
latest_by_group[group] = document
entries: list[PackageEntry] = [
PackageEntry(
zip_path=f"{document.address} ({document.landlord_property_id})/"
f"{document.document_type}",
s3_bucket=document.s3_bucket,
s3_key=document.s3_key,
)
for document in latest_by_group.values()
]
return DownloadPackagePlan(entries=tuple(entries), skipped=())