Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions legal-api/src/legal_api/models/business.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from legal_api.exceptions import BusinessException
from legal_api.utils.base import BaseEnum
from legal_api.utils.datetime import datetime, timezone
from legal_api.utils.datetime import datetime
from legal_api.utils.legislation_datetime import LegislationDatetime

from .address import Address
Expand Down Expand Up @@ -335,13 +335,10 @@ def business_legal_name(self):
@property
def next_anniversary(self):
"""Retrieve the next anniversary date for which an AR filing is due."""
if not self.founding_date and not self.last_ar_date:
return None
last_anniversary = self.founding_date
if self.last_ar_date:
last_anniversary = self.last_ar_date

return last_anniversary + datedelta.datedelta(years=1)
_founding_date = LegislationDatetime.as_legislation_timezone(self.founding_date)
next_ar_year = (self.last_ar_year if self.last_ar_year else self.founding_date.year) + 1
no_of_years_to_add = next_ar_year - _founding_date.year
return _founding_date + datedelta.datedelta(years=no_of_years_to_add)

@property
def next_annual_tr_due_datetime(self) -> datetime:
Expand Down Expand Up @@ -443,7 +440,7 @@ def get_ar_dates(self, next_ar_year):
ar_min_date = _founding_date.date() + datedelta.datedelta(years=no_of_years_to_add)
ar_max_date = ar_min_date + datedelta.datedelta(days=60)

ar_max_date = min(ar_max_date, datetime.utcnow().date()) # ar_max_date cannot be in future
ar_max_date = min(ar_max_date, LegislationDatetime.datenow()) # ar_max_date cannot be in future

return ar_min_date, ar_max_date

Expand Down Expand Up @@ -610,9 +607,7 @@ def json(self, slim=False):
"naicsKey": self.naics_key,
"naicsCode": self.naics_code,
"naicsDescription": self.naics_description,
"nextAnnualReport": LegislationDatetime.as_legislation_timezone_from_date(
self.next_anniversary
).astimezone(timezone.utc).isoformat() if self.next_anniversary else "",
"nextAnnualReport": self.next_anniversary.isoformat(),
"noDissolution": self.no_dissolution,
"associationType": self.association_type,
"allowedActions": self.allowable_actions,
Expand Down
6 changes: 6 additions & 0 deletions legal-api/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ def _utcnow_side_effect():
return datetime.now(tz=timezone.utc)
monkey_session.setattr('legal_api.utils.datetime.datetime.utcnow', _utcnow_side_effect)


def _now_side_effect():
"""super().now() is not supported by freezegun, so we mock datetime.now() directly."""
return datetime.now()
monkey_session.setattr('legal_api.utils.datetime.datetime.now', _now_side_effect)

return _app


Expand Down
10 changes: 5 additions & 5 deletions legal-api/tests/unit/models/test_business.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ def test_business_json(session):
last_ledger_timestamp=EPOCH_DATETIME,
identifier='CP1234567',
last_modified=EPOCH_DATETIME,
last_ar_date=EPOCH_DATETIME,
last_agm_date=EPOCH_DATETIME,
last_ar_date=None,
last_agm_date=None,
restriction_ind=True,
association_type='CP',
# NB: default not intitialized since bus not committed before check
Expand Down Expand Up @@ -354,12 +354,12 @@ def test_business_json(session):
'lastDirectorChangeDate': '',
'lastLedgerTimestamp': EPOCH_DATETIME.isoformat(),
'lastModified': EPOCH_DATETIME.isoformat(),
'lastAnnualReportDate': datetime.date(EPOCH_DATETIME).isoformat(),
'lastAnnualGeneralMeetingDate': datetime.date(EPOCH_DATETIME).isoformat(),
'lastAnnualReportDate': '',
'lastAnnualGeneralMeetingDate': '',
'naicsKey': None,
'naicsCode': None,
'naicsDescription': None,
'nextAnnualReport': '1971-01-01T08:00:00+00:00',
'nextAnnualReport': '1971-12-31T16:00:00-08:00',
'hasRestrictions': True,
'arMinDate': '1971-01-01',
'arMaxDate': '1972-04-30',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ def test_validate_ar_year(app, test_name, current_ar_date, previous_ar_date, fou
'2020-01-01', '2021-10-31', None, 2020, '2022-07-14'),
])
def test_ar_dates(
app, session, test_name, founding_date, previous_ar_date, legal_type, expected_ar_min_date,
expected_ar_max_date, previous_ar_year, next_year, today):
app, session, test_name, founding_date, previous_ar_date, legal_type,
expected_ar_min_date, expected_ar_max_date, previous_ar_year, next_year, today):
"""Assert min and max dates for Annual Report are correct."""
now = datetime.fromisoformat(today)
now = datetime.fromisoformat(today + 'T12:00:00+00:00')
with freeze_time(now):
# setup
previous_ar_datetime = datetime.fromisoformat(previous_ar_date) if previous_ar_date else None
Expand Down
2 changes: 1 addition & 1 deletion python/common/business-registry-model/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "business-model"
version = "3.3.14"
version = "3.3.16"
description = ""
authors = [
{name = "thor",email = "1042854+thorwolpert@users.noreply.github.com"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,10 @@ def business_legal_name(self):
@property
def next_anniversary(self):
"""Retrieve the next anniversary date for which an AR filing is due."""
if not self.founding_date and not self.last_ar_date:
return None
last_anniversary = self.founding_date
if self.last_ar_date:
last_anniversary = self.last_ar_date

return last_anniversary + datedelta.datedelta(years=1)
_founding_date = LegislationDatetime.as_legislation_timezone(self.founding_date)
next_ar_year = (self.last_ar_year if self.last_ar_year else self.founding_date.year) + 1
no_of_years_to_add = next_ar_year - _founding_date.year
return _founding_date + datedelta.datedelta(years=no_of_years_to_add)

@property
def next_annual_tr_due_datetime(self) -> datetime:
Expand Down Expand Up @@ -465,7 +462,7 @@ def get_ar_dates(self, next_ar_year):
ar_min_date = self.founding_date.date() + datedelta.datedelta(years=no_of_years_to_add)
ar_max_date = ar_min_date + datedelta.datedelta(days=60)

ar_max_date = min(ar_max_date, datetime.utcnow().date()) # ar_max_date cannot be in future
ar_max_date = min(ar_max_date, LegislationDatetime.datenow()) # ar_max_date cannot be in future

return ar_min_date, ar_max_date

Expand Down Expand Up @@ -634,9 +631,7 @@ def json(self, slim=False):
'naicsKey': self.naics_key,
'naicsCode': self.naics_code,
'naicsDescription': self.naics_description,
'nextAnnualReport': LegislationDatetime.as_legislation_timezone_from_date(
self.next_anniversary
).astimezone(timezone.utc).isoformat() if self.next_anniversary else '',
'nextAnnualReport': self.next_anniversary.isoformat(),
'noDissolution': self.no_dissolution,
'associationType': self.association_type,
'allowedActions': self.allowable_actions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ def test_business_json(app, session):
last_ledger_timestamp=EPOCH_DATETIME,
identifier='CP1234567',
last_modified=EPOCH_DATETIME,
last_ar_date=EPOCH_DATETIME,
last_agm_date=EPOCH_DATETIME,
last_ar_date=None,
last_agm_date=None,
restriction_ind=True,
association_type='CP',
# NB: default not intitialized since bus not committed before check
Expand Down Expand Up @@ -365,12 +365,12 @@ def test_business_json(app, session):
'lastDirectorChangeDate': '',
'lastLedgerTimestamp': EPOCH_DATETIME.isoformat(),
'lastModified': EPOCH_DATETIME.isoformat(),
'lastAnnualReportDate': datetime.date(EPOCH_DATETIME).isoformat(),
'lastAnnualGeneralMeetingDate': datetime.date(EPOCH_DATETIME).isoformat(),
'lastAnnualReportDate': '',
'lastAnnualGeneralMeetingDate': '',
'naicsKey': None,
'naicsCode': None,
'naicsDescription': None,
'nextAnnualReport': '1971-01-01T08:00:00+00:00',
'nextAnnualReport': '1971-12-31T16:00:00-08:00',
'hasRestrictions': True,
'arMinDate': '1971-01-01',
'arMaxDate': '1972-04-30',
Expand Down
Loading