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

Skip to content

Commit a3d597f

Browse files
34481 validation for newLegalType and resolutionDates (new format) (#4683)
1 parent 81c49b3 commit a3d597f

4 files changed

Lines changed: 314 additions & 31 deletions

File tree

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ def validate(business: Business, filing: dict) -> Error: # pylint: disable=too-
4646
error = PermissionService.check_user_permission(required_permission, message=message)
4747
if error:
4848
return error
49-
msg.extend(type_change_validation(filing, business))
50-
msg.extend(company_name_validation(filing, business))
51-
msg.extend(share_structure_validation(filing, business))
49+
new_legal_type_path: Final = "/filing/alteration/business/legalType"
50+
new_legal_type = get_str(filing, new_legal_type_path)
51+
msg.extend(validate_type_change(filing, business, new_legal_type_path))
52+
msg.extend(company_name_validation(filing, business, new_legal_type))
53+
msg.extend(share_structure_validation(filing, business, new_legal_type))
5254
msg.extend(court_order_validation(filing))
5355
msg.extend(rules_change_validation(filing))
5456
msg.extend(memorandum_change_validation(filing))
@@ -80,10 +82,9 @@ def court_order_validation(filing):
8082
return []
8183

8284

83-
def share_structure_validation(filing, business: Business):
85+
def share_structure_validation(filing, business: Business, new_legal_type: str):
8486
"""Validate share structure."""
8587
share_structure_path: Final = "/filing/alteration/shareStructure"
86-
new_legal_type = get_str(filing, "/filing/alteration/business/legalType")
8788

8889
if get_str(filing, share_structure_path):
8990
err = validate_share_structure(filing, "alteration", new_legal_type or business.legal_type)
@@ -95,13 +96,12 @@ def share_structure_validation(filing, business: Business):
9596
return []
9697

9798

98-
def company_name_validation(filing, business: Business):
99+
def company_name_validation(filing, business: Business, new_legal_type: str):
99100
"""Validate company name."""
100101
msg = []
101102
if filing["filing"]["header"].get("source") == "COLIN":
102103
return msg
103104

104-
new_legal_type = get_str(filing, "/filing/alteration/business/legalType")
105105
if get_str(filing, "/filing/alteration/nameRequest/nrNumber"):
106106
accepted_request_types = [
107107
"BEC", "CCC", "CCP", "CCR", "CUL", # name change types
@@ -126,10 +126,9 @@ def company_name_validation(filing, business: Business):
126126
return msg
127127

128128

129-
def type_change_validation(filing, business: Business):
129+
def validate_type_change(filing, business: Business, legal_type_path: str):
130130
"""Validate type change."""
131131
msg = []
132-
legal_type_path: Final = "/filing/alteration/business/legalType"
133132
new_legal_type = get_str(filing, legal_type_path)
134133

135134
# Valid type changes

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

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def validate_resolution_date_in_share_structure(filing_json, filing_type, busine
112112
113113
Rules:
114114
- If hasRightsOrRestrictions is true in any share class or series, resolution date is required.
115-
- Only one resolution date is permitted.
115+
- Only one resolution date is permitted (alteration and old correction).
116116
- Resolution date cannot be in the future.
117117
- Resolution date cannot be before the business founding date.
118118
"""
@@ -121,7 +121,7 @@ def validate_resolution_date_in_share_structure(filing_json, filing_type, busine
121121
resolution_dates = share_structure.get("resolutionDates", [])
122122

123123
err_path = f"/filing/{filing_type}/shareStructure/resolutionDates"
124-
124+
125125
msg = []
126126
if (
127127
(
@@ -135,29 +135,57 @@ def validate_resolution_date_in_share_structure(filing_json, filing_type, busine
135135
"path": err_path
136136
})
137137

138+
if not resolution_dates:
139+
return msg
140+
141+
if isinstance(resolution_dates[0], str):
142+
# Kept for backward compatibility (existing alteration and correction filings)
143+
msg.extend(_validate_resolution_dates_old_format(resolution_dates, business, err_path))
144+
else:
145+
# Did not include "Only one resolution date is permitted.", not required for correction
146+
# If its required for alteration add while updating alteration filing
147+
existing_ids = {resolution.id for resolution in business.resolutions.all()}
148+
for idx, resolution_date in enumerate(resolution_dates):
149+
if (resolution_id := resolution_date.get("id")) and (resolution_id not in existing_ids):
150+
msg.append({
151+
"error": "Not a valid Resolution Id for this business.",
152+
"path": f"{err_path}/{idx}"
153+
})
154+
else:
155+
msg.extend(_validate_resolution_date(resolution_date["date"], business, f"{err_path}/{idx}"))
156+
157+
return msg
158+
159+
def _validate_resolution_dates_old_format(resolution_dates, business, err_path):
160+
msg = []
138161
if len(resolution_dates) > 1:
139162
msg.append({
140163
"error": "Only one resolution date is permitted.",
141164
"path": err_path
142165
})
143166

144167
elif len(resolution_dates) == 1:
145-
resolution_date_leg = date.fromisoformat(resolution_dates[0])
146-
founding_date_leg = LegislationDatetime.as_legislation_timezone(business.founding_date).date()
147-
today_leg = LegislationDatetime.datenow()
168+
msg.extend(_validate_resolution_date(resolution_dates[0], business, err_path))
148169

149-
if resolution_date_leg > today_leg:
150-
msg.append({
151-
"error": "Resolution date cannot be in the future.",
152-
"path": err_path
153-
})
170+
return msg
154171

155-
if resolution_date_leg < founding_date_leg:
156-
msg.append({
157-
"error": "Resolution date cannot be before the business founding date.",
158-
"path": err_path
159-
})
172+
def _validate_resolution_date(resolution_date_str: str, business, err_path: str) -> list[dict]:
173+
resolution_date = date.fromisoformat(resolution_date_str)
174+
founding_date = LegislationDatetime.as_legislation_timezone(business.founding_date).date()
175+
today = LegislationDatetime.datenow()
176+
177+
msg = []
178+
if resolution_date > today:
179+
msg.append({
180+
"error": "Resolution date cannot be in the future.",
181+
"path": err_path
182+
})
160183

184+
if resolution_date < founding_date:
185+
msg.append({
186+
"error": "Resolution date cannot be before the business founding date.",
187+
"path": err_path
188+
})
161189
return msg
162190

163191

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from legal_api.core.filing_helper import is_special_resolution_correction_by_filing_json
2525
from legal_api.errors import Error
2626
from legal_api.services import STAFF_ROLE, SYSTEM_ROLE, NaicsService
27+
from legal_api.services.filings.validations.alteration import validate_type_change
2728
from legal_api.services.filings.validations.common_validations import (
2829
validate_court_order,
2930
validate_name_request,
@@ -129,6 +130,13 @@ def _validate_firms_correction(business: Business, filing, legal_type, msg):
129130

130131
def _validate_corps_correction(business: Business, filing_dict, legal_type, msg):
131132
filing_type = "correction"
133+
if new_legal_type := filing_dict.get("filing", {}).get("correction", {}).get("newLegalType"):
134+
if business.legal_type == new_legal_type:
135+
# This is not a valid type change
136+
path = "/filing/correction/newLegalType"
137+
msg.append({"error": _("New legal type must be different from current legal type."), "path": path})
138+
else:
139+
msg.extend(validate_type_change(filing_dict, business, "/filing/correction/newLegalType"))
132140
if filing_dict.get("filing", {}).get("correction", {}).get("nameRequest", {}).get("nrNumber", None):
133141
msg.extend(validate_name_request(filing_dict, legal_type, filing_type))
134142
if filing_dict.get("filing", {}).get("correction", {}).get("offices", None):
@@ -144,13 +152,8 @@ def _validate_corps_correction(business: Business, filing_dict, legal_type, msg)
144152
if err:
145153
msg.extend(err)
146154

147-
err = validate_share_currency(filing_dict, filing_type, business)
148-
if err:
149-
msg.extend(err)
150-
151-
err = validate_resolution_date_in_share_structure(filing_dict, filing_type, business)
152-
if err:
153-
msg.extend(err)
155+
msg.extend(validate_share_currency(filing_dict, filing_type, business))
156+
msg.extend(validate_resolution_date_in_share_structure(filing_dict, filing_type, business))
154157

155158

156159
def _validate_special_resolution_correction(filing_dict, legal_type, msg):

0 commit comments

Comments
 (0)