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

Skip to content

Commit 26cfc7a

Browse files
34490 process newLegalType and resolutionDates in correction (#4765)
1 parent 0037746 commit 26cfc7a

10 files changed

Lines changed: 240 additions & 120 deletions

File tree

legal-api/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,4 @@ ENV PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
8989

9090
COPY --chown=web:web . /code
9191

92-
CMD gunicorn --bind 0.0.0.0:${PORT} --config /code/gunicorn_config.py wsgi:application
92+
CMD gunicorn --bind 0.0.0.0:${PORT} --config /code/gunicorn_config.py wsgi:application

legal-api/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "legal-api"
3-
version = "3.1.25"
3+
version = "3.1.26"
44
description = ""
55
authors = [
66
{name = "thor",email = "[email protected]"}

legal-api/src/legal_api/services/filings/validations/correction.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ def _validate_corps_correction_active(business: Business, filing_dict, legal_typ
214214
msg.append({"error": _("New legal type must be different from current legal type."), "path": path})
215215
else:
216216
msg.extend(validate_type_change(filing_dict, business, "/filing/correction/newLegalType"))
217-
if filing_dict.get("filing", {}).get("correction", {}).get("nameRequest", {}).get("nrNumber", None):
218-
msg.extend(validate_name_request(filing_dict, legal_type, filing_type))
217+
msg.extend(_validate_name_request(business, filing_dict, new_legal_type, filing_type))
218+
219219
if filing_dict.get("filing", {}).get("correction", {}).get("offices", None):
220220
msg.extend(validate_corp_offices(filing_dict, legal_type, filing_type))
221221
if filing_dict.get("filing", {}).get("correction", {}).get("parties", None):
@@ -253,6 +253,25 @@ def _validate_corps_correction_active(business: Business, filing_dict, legal_typ
253253
msg.extend(_validate_amalgamation_correction(filing_dict, filing_type, business))
254254

255255

256+
def _validate_name_request(business, filing_dict, new_legal_type, filing_type):
257+
msg = []
258+
if filing_dict.get("filing", {}).get("correction", {}).get("nameRequest", {}).get("nrNumber", None):
259+
msg.extend(validate_name_request(filing_dict, new_legal_type or business.legal_type, filing_type))
260+
else:
261+
valid_names = [business.legal_name]
262+
if (new_legal_type and
263+
(new_numbered_name := Business.generate_numbered_legal_name(new_legal_type, business.identifier))):
264+
# if existing legal_name is a numbered name and if type has changed
265+
# then the legal name get updated according to the new legal type
266+
valid_names.append(new_numbered_name)
267+
268+
nr_legal_name_path = f"/filing/{filing_type}/nameRequest/legalName"
269+
new_legal_name = get_str(filing_dict, nr_legal_name_path)
270+
if new_legal_name and new_legal_name not in valid_names:
271+
msg.append({"error": _("Unexpected legal name."), "path": nr_legal_name_path})
272+
return msg
273+
274+
256275
def _validate_court_orders_correction(filing_dict, business: Business):
257276
"""Validate court orders for a correction filing.
258277

legal-api/tests/unit/services/filings/validations/test_correction_ia.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ def test_correction_share_class_series_validation(session, app, jwt, legal_type,
296296
filing['filing']['correction']['correctedFilingId'] = corrected_filing.id
297297
filing['filing']['business']['legalType'] = legal_type
298298
del filing['filing']['correction']['commentOnly']
299+
del filing['filing']['correction']['nameRequest']
299300

300301
if legal_type == 'CC':
301302
director = copy.deepcopy(filing['filing']['correction']['parties'][0])
@@ -367,6 +368,7 @@ def test_correction_resolution_date_old(session, app, jwt, test_name, has_rights
367368
filing['filing']['header']['identifier'] = identifier
368369
filing['filing']['correction']['correctedFilingId'] = corrected_filing.id
369370
del filing['filing']['correction']['commentOnly']
371+
del filing['filing']['correction']['nameRequest']
370372

371373
# Share structure setup
372374
filing['filing']['correction']['shareStructure'] = copy.deepcopy(
@@ -447,6 +449,7 @@ def test_correction_resolution_date(session, app, jwt, test_name, has_rights_or_
447449
filing['filing']['header']['identifier'] = identifier
448450
filing['filing']['correction']['correctedFilingId'] = corrected_filing.id
449451
del filing['filing']['correction']['commentOnly']
452+
del filing['filing']['correction']['nameRequest']
450453

451454
# Share structure setup
452455
filing['filing']['correction']['shareStructure'] = copy.deepcopy(
@@ -673,6 +676,7 @@ def test_validate_correction_continuation_in_incorporation_date(mocker, app, ses
673676
}
674677
filing['filing']['business']['legalType'] = 'C'
675678
del filing['filing']['correction']['commentOnly']
679+
del filing['filing']['correction']['nameRequest']
676680
factory_jurisdiction(
677681
business_id=business.id,
678682
filing_id=corrected_filing.id,
@@ -774,6 +778,7 @@ def test_validate_continuation_in_field_lengths(mocker, app, session, jwt,
774778
}
775779
filing['filing']['business']['legalType'] = 'C'
776780
del filing['filing']['correction']['commentOnly']
781+
del filing['filing']['correction']['nameRequest']
777782

778783
factory_jurisdiction(
779784
business_id=business.id,
@@ -822,6 +827,7 @@ def test_validate_continuation_in_expro_founding_date_match(mocker, app, session
822827
}
823828
filing['filing']['business']['legalType'] = 'C'
824829
del filing['filing']['correction']['commentOnly']
830+
del filing['filing']['correction']['nameRequest']
825831
factory_jurisdiction(
826832
business_id=business.id,
827833
filing_id=corrected_filing.id,
@@ -872,6 +878,7 @@ def test_validate_correction_continuation_in_existing_foreign_jurisdiction(mocke
872878
}
873879
filing['filing']['business']['legalType'] = 'C'
874880
del filing['filing']['correction']['commentOnly']
881+
del filing['filing']['correction']['nameRequest']
875882
factory_jurisdiction(
876883
business_id=business.id,
877884
filing_id=corrected_filing.id,
@@ -1065,7 +1072,7 @@ def test_validate_correction_amalgamation_ting_not_found(mocker, app, session, j
10651072
filing['filing']['correction']['amalgamation'] = data
10661073
filing['filing']['business']['legalType'] = 'BC'
10671074
del filing['filing']['correction']['commentOnly']
1068-
1075+
del filing['filing']['correction']['nameRequest']
10691076

10701077
with jwt_request_context(app, jwt, [BASIC_USER]):
10711078
err = validate(business, filing)
@@ -1110,6 +1117,7 @@ def test_validate_correction_amalgamation_foreign_jurisdiction(mocker, app, sess
11101117
filing['filing']['correction']['amalgamation'] = data
11111118
filing['filing']['business']['legalType'] = 'BC'
11121119
del filing['filing']['correction']['commentOnly']
1120+
del filing['filing']['correction']['nameRequest']
11131121

11141122
with jwt_request_context(app, jwt, [BASIC_USER]):
11151123
err = validate(business, filing)
@@ -1149,6 +1157,7 @@ def test_validate_correction_amalgamation_existing_foreign_jurisdiction(mocker,
11491157
filing['filing']['correction']['amalgamation'] = data
11501158
filing['filing']['business']['legalType'] = 'BC'
11511159
del filing['filing']['correction']['commentOnly']
1160+
del filing['filing']['correction']['nameRequest']
11521161

11531162
with jwt_request_context(app, jwt, [BASIC_USER]):
11541163
err = validate(business, filing)
@@ -1181,7 +1190,7 @@ def test_validate_correction_amalgamation_ting_invalid(mocker, app, session, jwt
11811190
filing['filing']['correction']['amalgamation'] = data
11821191
filing['filing']['business']['legalType'] = 'BC'
11831192
del filing['filing']['correction']['commentOnly']
1184-
1193+
del filing['filing']['correction']['nameRequest']
11851194

11861195
with jwt_request_context(app, jwt, [BASIC_USER]):
11871196
err = validate(business, filing)
@@ -1224,6 +1233,7 @@ def test_validate_correction_amalgamation_colin_ting(mocker, app, session, jwt):
12241233
filing['filing']['correction']['amalgamation'] = data
12251234
filing['filing']['business']['legalType'] = 'BC'
12261235
del filing['filing']['correction']['commentOnly']
1236+
del filing['filing']['correction']['nameRequest']
12271237

12281238
with jwt_request_context(app, jwt, [BASIC_USER]):
12291239
err = validate(business, filing)

queue_services/business-filer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@ COPY --chown=web:web . /code
8787

8888
# ENV PYTHONPATH=/opt/app-root/src
8989

90-
CMD gunicorn --bind 0.0.0.0:${PORT} --preload --config /code/gunicorn_config.py wsgi:app
90+
CMD gunicorn --bind 0.0.0.0:${PORT} --preload --config /code/gunicorn_config.py wsgi:app

queue_services/business-filer/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "business-filer"
3-
version = "3.0.30"
3+
version = "3.0.31"
44
description = "Business Registry Filer Service"
55
authors = [
66
{name = "thor",email = "[email protected]"}

queue_services/business-filer/src/business_filer/filing_processors/filing_components/correction.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,40 @@ def correct_business_data(business: Business, # noqa: PLR0915
7474
correction_filing: dict,
7575
filing_meta: FilingMeta):
7676
"""Render the correction filing onto the business model objects."""
77+
to_legal_type = None
78+
with suppress(IndexError, KeyError, TypeError):
79+
to_legal_type = dpath.get(correction_filing, "/correction/newLegalType")
80+
if to_legal_type and business.legal_type != to_legal_type:
81+
filing_meta.correction = {
82+
**filing_meta.correction,
83+
"fromLegalType": business.legal_type,
84+
"toLegalType": to_legal_type
85+
}
86+
business_info.set_corp_type(business, {"legalType": to_legal_type})
87+
7788
# Update business legalName if present
7889
with suppress(IndexError, KeyError, TypeError):
7990
name_request_json = dpath.get(correction_filing, "/correction/nameRequest")
8091
from_legal_name = business.legal_name
81-
business_info.set_legal_name(business.identifier, business, name_request_json)
92+
business_info.set_legal_name(business.identifier, business, name_request_json, to_legal_type)
8293
if from_legal_name != business.legal_name:
83-
filing_meta.correction = {**filing_meta.correction,
84-
"fromLegalName": from_legal_name,
85-
"toLegalName": business.legal_name}
94+
filing_meta.correction = {
95+
**filing_meta.correction,
96+
"fromLegalName": from_legal_name,
97+
"toLegalName": business.legal_name
98+
}
8699

87100
# Update cooperativeAssociationType if present
88101
with suppress(IndexError, KeyError, TypeError):
89102
coop_association_type = dpath.get(correction_filing, "/correction/cooperativeAssociationType")
90103
from_association_type = business.association_type
91104
if coop_association_type:
92105
business_info.set_association_type(business, coop_association_type)
93-
filing_meta.correction = {**filing_meta.correction,
94-
"fromCooperativeAssociationType": from_association_type,
95-
"toCooperativeAssociationType": business.association_type}
106+
filing_meta.correction = {
107+
**filing_meta.correction,
108+
"fromCooperativeAssociationType": from_association_type,
109+
"toCooperativeAssociationType": business.association_type
110+
}
96111

97112
# Update Nature of Business
98113
if naics := correction_filing.get("correction", {}).get("business", {}).get("naics"):
@@ -102,8 +117,9 @@ def correct_business_data(business: Business, # noqa: PLR0915
102117
filing_meta.correction = {
103118
**filing_meta.correction,
104119
"fromNaicsCode": business.naics_code,
105-
"toNaicsCode": to_naics_code,
106-
"naicsDescription": to_naics_description}
120+
"toNaicsCode": to_naics_code,
121+
"naicsDescription": to_naics_description
122+
}
107123
business_info.update_naics_info(business, naics)
108124

109125
# update name translations, if any

queue_services/business-filer/src/business_filer/filing_processors/filing_components/shares.py

Lines changed: 48 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -34,69 +34,67 @@
3434
"""Manages the share structure for a business."""
3535
from __future__ import annotations
3636

37+
from datetime import date
38+
3739
from business_model.models import Business, Resolution, ShareClass, ShareSeries
38-
from dateutil.parser import parse
3940

4041

41-
def update_resolution_dates(business: Business, share_structure: dict) -> list | None:
42+
def update_resolution_dates(business: Business, share_structure: dict) -> None:
4243
"""Update the business resolution dates from a share structure."""
4344
if not business or not share_structure:
4445
# if nothing is passed in, we don't care and it's not an error
45-
return None
46-
47-
err = []
48-
49-
if resolution_dates := share_structure.get("resolutionDates"):
50-
for resolution_dt in resolution_dates:
51-
try:
52-
d = Resolution(
53-
resolution_date=parse(resolution_dt).date(),
46+
return
47+
48+
if "resolutionDates" in share_structure:
49+
resolution_dates = share_structure.get("resolutionDates", [])
50+
# This will fail to remove resolutions if the resolutionDates list is empty
51+
# TODO: Update alteration and move to new correction to use new format, then update this code
52+
# Ticket: https://app.zenhub.com/workspaces/colin-egress-team-6904d552be2bb0000fa13ad6/issues/gh/bcgov/entity/34841
53+
if len(resolution_dates) > 0 and isinstance(resolution_dates[0], dict):
54+
for current_resolution in business.resolutions.all():
55+
if not next((x for x in resolution_dates if x.get("id") == current_resolution.id), None):
56+
business.resolutions.remove(current_resolution)
57+
58+
for resolution_date in resolution_dates:
59+
if (
60+
(resolution_id := resolution_date.get("id")) and
61+
(resolution := business.resolutions.filter_by(id=resolution_id).one_or_none())
62+
):
63+
resolution.resolution_date = date.fromisoformat(resolution_date["date"])
64+
business.resolutions.append(resolution)
65+
else:
66+
resolution = Resolution(
67+
resolution_date=date.fromisoformat(resolution_date["date"]),
68+
resolution_type=Resolution.ResolutionType.SPECIAL.value
69+
)
70+
business.resolutions.append(resolution)
71+
else:
72+
# Kept for backward compatibility (existing alteration and correction filings)
73+
for resolution_dt in resolution_dates:
74+
resolution = Resolution(
75+
resolution_date=date.fromisoformat(resolution_dt),
5476
resolution_type=Resolution.ResolutionType.SPECIAL.value
5577
)
56-
business.resolutions.append(d)
57-
except (ValueError, OverflowError):
58-
err.append(
59-
{"error_code": "FILER_INVALID_RESOLUTION_DATE",
60-
"error_message": f"Filer: invalid resolution date:'{resolution_dt}'"}
61-
)
78+
business.resolutions.append(resolution)
6279

63-
return err
6480

65-
def update_share_structure(business: Business, share_structure: dict) -> list | None:
81+
def update_share_structure(business: Business, share_structure: dict) -> None:
6682
"""Manage the share structure for a business.
6783
6884
Assumption: The structure has already been validated, upon submission.
6985
7086
Other errors are recorded and will be managed out of band.
7187
"""
72-
err = []
73-
74-
err = update_resolution_dates(business, share_structure)
88+
update_resolution_dates(business, share_structure)
7589

7690
if share_classes := share_structure.get("shareClasses"):
77-
try:
78-
delete_existing_shares(business)
79-
except:
80-
err.append(
81-
{"error_code": "FILER_UNABLE_TO_DELETE_SHARES",
82-
"error_message": f"Filer: unable to delete shares for :'{business.identifier}'"}
83-
)
84-
# we're FUBAR, do not load the new shares
85-
return err
86-
87-
try:
88-
for share_class_info in share_classes:
89-
share_class = create_share_class(share_class_info)
90-
business.share_classes.append(share_class)
91-
except KeyError:
92-
err.append(
93-
{"error_code": "FILER_UNABLE_TO_SAVE_SHARES",
94-
"error_message": f"Filer: unable to save new shares for :'{business.identifier}'"}
95-
)
96-
97-
return err
98-
99-
def update_share_structure_correction(business: Business, share_structure: dict) -> list | None:
91+
delete_existing_shares(business)
92+
for share_class_info in share_classes:
93+
share_class = create_share_class(share_class_info)
94+
business.share_classes.append(share_class)
95+
96+
97+
def update_share_structure_correction(business: Business, share_structure: dict) -> None:
10098
"""Manage the share structure for a business.
10199
102100
Assumption: The structure has already been validated, upon submission.
@@ -105,9 +103,9 @@ def update_share_structure_correction(business: Business, share_structure: dict)
105103
"""
106104
if not business or not share_structure:
107105
# if nothing is passed in, we don't care and it's not an error
108-
return None
106+
return
109107

110-
err = update_resolution_dates(business, share_structure)
108+
update_resolution_dates(business, share_structure)
111109

112110
if share_classes := share_structure.get("shareClasses"):
113111
# Entries in json and not in db
@@ -116,17 +114,9 @@ def update_share_structure_correction(business: Business, share_structure: dict)
116114
# Update existing ones in both db and json, append the ones only in json into exclusion entires
117115
update_business_share_class(share_classes, business, exclusion_entries)
118116

119-
try:
120-
for share_class_info in exclusion_entries:
121-
share_class = create_share_class(share_class_info)
122-
business.share_classes.append(share_class)
123-
except KeyError:
124-
err.append(
125-
{"error_code": "FILER_UNABLE_TO_SAVE_SHARES",
126-
"error_message": f"Filer: unable to save new shares for :'{business.identifier}'"}
127-
)
128-
129-
return err
117+
for share_class_info in exclusion_entries:
118+
share_class = create_share_class(share_class_info)
119+
business.share_classes.append(share_class)
130120

131121

132122
def delete_existing_shares(business: Business):

0 commit comments

Comments
 (0)