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
11 changes: 10 additions & 1 deletion legal-api/src/legal_api/resources/v2/business/business_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,16 @@ def construct_task_list(business: Business): # noqa: PLR0915
tasks.append(task)
order += 1

if business.legal_type not in entity_types_no_ar and not business.in_liquidation:
# Skip AR todos when founding date is the COLIN year 0001 (for legacy data like railways). Without this,
# a sentinel founding_date of 0001-01-01 generates ~2000 AR todos and a multi-MB /tasks payload.
unknown_founding_date = (
not business.founding_date or business.founding_date.year <= 1
)
if (
business.legal_type not in entity_types_no_ar
and not business.in_liquidation
and not unknown_founding_date
):
# If this is the first calendar year since incorporation, there is no previous ar year.
next_ar_year = (business.last_ar_year if business.last_ar_year else business.founding_date.year) + 1

Expand Down
23 changes: 21 additions & 2 deletions legal-api/tests/unit/resources/v2/test_business_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,26 @@ def test_get_tasks_no_filings(session, client, jwt):

rv = client.get(f'/api/v2/businesses/{identifier}/tasks', headers=create_header(jwt, [STAFF_ROLE], identifier))
assert rv.status_code == HTTPStatus.OK
assert num_filings_owed == len(rv.json.get('tasks'))
assert len(rv.json.get('tasks')) == num_filings_owed


def test_get_tasks_sentinel_founding_date_skips_ar(session, client, jwt):
"""Assert COLIN year-1 sentinel founding date does not generate thousands of AR todos."""
identifier = 'BC1234567'
factory_business(
identifier,
founding_date=datetime(1, 1, 1, 8, 0, 0, tzinfo=UTC),
entity_type=Business.LegalTypes.COMP.value,
state=Business.State.ACTIVE,
)

rv = client.get(f'/api/v2/businesses/{identifier}/tasks', headers=create_header(jwt, [STAFF_ROLE], identifier))
assert rv.status_code == HTTPStatus.OK
ar_tasks = [
t for t in rv.json.get('tasks')
if t.get('task', {}).get('todo', {}).get('header', {}).get('name') == 'annualReport'
]
assert len(ar_tasks) == 0


def test_get_tasks_next_year(session, client, jwt):
Expand All @@ -107,7 +126,7 @@ def test_get_tasks_next_year(session, client, jwt):

rv = client.get(f'/api/v2/businesses/{identifier}/tasks', headers=create_header(jwt, [STAFF_ROLE], identifier))
assert rv.status_code == HTTPStatus.OK
assert 1 == len(rv.json.get('tasks'))
assert len(rv.json.get('tasks')) == 1


def test_bcorps_get_tasks_no_filings(session, client, jwt):
Expand Down