Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf78416

Browse files
authored
34514 fix tasks load for legacy data with year 1 founding date (#4742)
* 34514 fix tasks load for legacy data with year 1 founding date * comment * fix unit test * fixed SC issue
1 parent c476f11 commit cf78416

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

legal-api/src/legal_api/resources/v2/business/business_tasks.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,16 @@ def construct_task_list(business: Business): # noqa: PLR0915
151151
tasks.append(task)
152152
order += 1
153153

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

legal-api/tests/unit/resources/v2/test_business_tasks.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,26 @@ def test_get_tasks_no_filings(session, client, jwt):
9494

9595
rv = client.get(f'/api/v2/businesses/{identifier}/tasks', headers=create_header(jwt, [STAFF_ROLE], identifier))
9696
assert rv.status_code == HTTPStatus.OK
97-
assert num_filings_owed == len(rv.json.get('tasks'))
97+
assert len(rv.json.get('tasks')) == num_filings_owed
98+
99+
100+
def test_get_tasks_sentinel_founding_date_skips_ar(session, client, jwt):
101+
"""Assert COLIN year-1 sentinel founding date does not generate thousands of AR todos."""
102+
identifier = 'BC1234567'
103+
factory_business(
104+
identifier,
105+
founding_date=datetime(1, 1, 1, 8, 0, 0, tzinfo=UTC),
106+
entity_type=Business.LegalTypes.COMP.value,
107+
state=Business.State.ACTIVE,
108+
)
109+
110+
rv = client.get(f'/api/v2/businesses/{identifier}/tasks', headers=create_header(jwt, [STAFF_ROLE], identifier))
111+
assert rv.status_code == HTTPStatus.OK
112+
ar_tasks = [
113+
t for t in rv.json.get('tasks')
114+
if t.get('task', {}).get('todo', {}).get('header', {}).get('name') == 'annualReport'
115+
]
116+
assert len(ar_tasks) == 0
98117

99118

100119
def test_get_tasks_next_year(session, client, jwt):
@@ -107,7 +126,7 @@ def test_get_tasks_next_year(session, client, jwt):
107126

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

112131

113132
def test_bcorps_get_tasks_no_filings(session, client, jwt):

0 commit comments

Comments
 (0)