From 63b23dc474f1e9abe10d669e832c12db8ee5b279 Mon Sep 17 00:00:00 2001 From: meawong Date: Thu, 3 Dec 2026 15:04:17 -0700 Subject: [PATCH] 35736 - Add arDueDate to business model --- .../business-registry-model/pyproject.toml | 2 +- .../src/business_model/models/business.py | 16 ++++- .../tests/models/test_business.py | 67 +++++++++++++++++++ 3 files changed, 82 insertions(+), 3 deletions(-) diff --git a/python/common/business-registry-model/pyproject.toml b/python/common/business-registry-model/pyproject.toml index a15b8c0716..19be9e1078 100644 --- a/python/common/business-registry-model/pyproject.toml +++ b/python/common/business-registry-model/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "business-model" -version = "3.4.32" +version = "3.4.33" description = "" authors = [ {name = "thor",email = "1042854+thorwolpert@users.noreply.github.com"} diff --git a/python/common/business-registry-model/src/business_model/models/business.py b/python/common/business-registry-model/src/business_model/models/business.py index fb12f75da5..7e35dc4cf9 100644 --- a/python/common/business-registry-model/src/business_model/models/business.py +++ b/python/common/business-registry-model/src/business_model/models/business.py @@ -469,8 +469,8 @@ def next_lr_min_date(self) -> datetime | None: years_to_add = next_lr_year - founding_date.year return founding_date + datedelta.datedelta(years=years_to_add) - def get_ar_dates(self, next_ar_year): - """Get ar min and max date for the specific year.""" + def _get_ar_date_values(self, next_ar_year): + """Get ar min date and uncapped max date for the specific year.""" ar_min_date = datetime(next_ar_year, 1, 1).date() ar_max_date = datetime(next_ar_year, 12, 31).date() covid_year = 2020 @@ -492,10 +492,22 @@ def get_ar_dates(self, next_ar_year): ar_max_date = ar_min_date + datedelta.datedelta(days=60) + return ar_min_date, ar_max_date + + def get_ar_dates(self, next_ar_year): + """Get ar min and max date for the specific year.""" + ar_min_date, ar_max_date = self._get_ar_date_values(next_ar_year) + ar_max_date = min(ar_max_date, LegislationDatetime.datenow()) # ar_max_date cannot be in future return ar_min_date, ar_max_date + def get_ar_due_date(self, next_ar_year): + """Get the uncapped annual report due date for the specific year.""" + _, ar_due_date = self._get_ar_date_values(next_ar_year) + + return ar_due_date + @property def mailing_address(self): """Return the mailing address.""" diff --git a/python/common/business-registry-model/tests/models/test_business.py b/python/common/business-registry-model/tests/models/test_business.py index 67a4390ed4..72b1845650 100644 --- a/python/common/business-registry-model/tests/models/test_business.py +++ b/python/common/business-registry-model/tests/models/test_business.py @@ -1055,3 +1055,70 @@ def test_next_lr_min_date(session, test_name, founding_date, in_liquidation_date assert business.next_lr_min_date == expected_lr_min_date + +@pytest.mark.parametrize( + 'legal_type, founding_date, next_ar_year, expected_min_date, expected_due_date', + [ + ( + Business.LegalTypes.COMP.value, + datetime(2025, 11, 22, 12, 0, tzinfo=UTC), + 2026, + date(2026, 11, 22), + date(2027, 1, 21), + ), + ( + Business.LegalTypes.COOP.value, + datetime(2020, 1, 1, tzinfo=UTC), + 2026, + date(2026, 1, 1), + date(2027, 4, 30), + ), + ( + Business.LegalTypes.COOP.value, + datetime(2019, 1, 1, tzinfo=UTC), + 2020, + date(2020, 1, 1), + date(2021, 10, 31), + ), + ( + Business.LegalTypes.SOLE_PROP.value, + datetime(2020, 1, 1, tzinfo=UTC), + 2026, + date(2026, 1, 1), + date(2026, 12, 31), + ), + ], +) +def test_get_ar_due_date( + legal_type, founding_date, next_ar_year, expected_min_date, expected_due_date +): + """Assert that the uncapped annual report due date is calculated correctly.""" + business = Business( + legal_type=legal_type, + founding_date=founding_date, + ) + + assert business.get_ar_due_date(next_ar_year) == expected_due_date + + ar_min_date, _ = business.get_ar_dates(next_ar_year) + assert ar_min_date == expected_min_date + + +def test_get_ar_dates_caps_max_date_at_today(monkeypatch): + """Assert that get_ar_dates continues to cap the maximum date at today.""" + today = date(2026, 12, 2) + monkeypatch.setattr(LegislationDatetime, 'datenow', lambda: today) + + business = Business( + legal_type=Business.LegalTypes.COMP.value, + founding_date=datetime(2025, 11, 22, 12, 0, tzinfo=UTC), + ) + + ar_min_date, ar_max_date = business.get_ar_dates(2026) + + assert ar_min_date == date(2026, 11, 22) + assert ar_max_date == today + + # The actual due date should remain uncapped. + assert business.get_ar_due_date(2026) == date(2027, 1, 21) +