diff --git a/domain/bulk_document_download/package_plan.py b/domain/bulk_document_download/package_plan.py index 6d08f6171..64e57950d 100644 --- a/domain/bulk_document_download/package_plan.py +++ b/domain/bulk_document_download/package_plan.py @@ -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=())