diff --git a/src/caselawclient/models/documents.py b/src/caselawclient/models/documents.py index 5d0a7183..e57824e3 100644 --- a/src/caselawclient/models/documents.py +++ b/src/caselawclient/models/documents.py @@ -216,6 +216,16 @@ def get_latest_manifestation_datetime( else: return max(events) + def get_latest_manifestation_type(self) -> Optional[str]: + return max( + ( + (type, time) + for type in ["transform", "tna-enriched"] + if (time := self.get_latest_manifestation_datetime(type)) + ), + key=lambda x: x[1], + )[0] + @cached_property def transformation_datetime(self) -> Optional[datetime.datetime]: return self.get_latest_manifestation_datetime("transform") diff --git a/tests/models/test_documents.py b/tests/models/test_documents.py index f096015d..d113b1f8 100644 --- a/tests/models/test_documents.py +++ b/tests/models/test_documents.py @@ -575,6 +575,7 @@ def test_dates(self, mock_api_client): assert document.enrichment_datetime.year == 2024 assert document.transformation_datetime.year == 2026 assert document.get_latest_manifestation_datetime().year == 2026 + assert document.get_latest_manifestation_type() == "transform" assert [ x.year for x in document.get_manifestation_datetimes("tna-enriched") ] == [2024, 2023]