1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414"""Validation for the Correction filing."""
15- from datetime import timedelta
15+ from datetime import UTC , datetime , timedelta
1616from http import HTTPStatus
1717from typing import Final
1818
4545 validate_continuation_in_expro_business_in_colin ,
4646 validate_continuation_in_foreign_jurisdiction ,
4747)
48+ from legal_api .services .filings .validations .dissolution import validate_custodian_email
4849from legal_api .services .filings .validations .incorporation_application import (
4950 validate_coop_parties_mailing_address ,
5051 validate_roles ,
@@ -97,21 +98,6 @@ def validate(business: Business, filing: dict) -> Error:
9798 if not is_comment_only_correction :
9899 if filing .get ("filing" , {}).get ("correction" , {}).get ("parties" , None ):
99100 msg .extend (validate_parties_addresses (filing , filing_type ))
100- if filing .get ("filing" , {}).get ("correction" , {}).get ("relationships" , None ):
101- msg .extend (validate_relationships (
102- business ,
103- filing ,
104- filing_type ,
105- [
106- PartyRole .RoleTypes .DIRECTOR ,
107- PartyRole .RoleTypes .LIQUIDATOR ,
108- PartyRole .RoleTypes .RECEIVER ,
109- PartyRole .RoleTypes .COMPLETING_PARTY
110- ],
111- True ,
112- True ,
113- [PartyRole .RoleTypes .DIRECTOR , PartyRole .RoleTypes .COMPLETING_PARTY ]
114- ))
115101 if filing .get ("filing" , {}).get ("correction" , {}).get ("offices" , None ):
116102 msg .extend (validate_offices_addresses (filing , filing_type ))
117103
@@ -145,6 +131,81 @@ def _validate_firms_correction(business: Business, filing, legal_type, msg):
145131
146132
147133def _validate_corps_correction (business : Business , filing_dict , legal_type , msg ):
134+ if filing_dict .get ("filing" , {}).get ("correction" , {}).get ("courtOrder" , None ):
135+ msg .extend (court_order_validation (filing_dict ))
136+ msg .extend (_validate_court_orders_correction (filing_dict , business ))
137+
138+ if relationships := filing_dict .get ("filing" , {}).get ("correction" , {}).get ("relationships" , None ):
139+ relationships_path = "/filing/correction/relationships"
140+ completing_parties = [
141+ x for x in relationships
142+ if any (
143+ role for role in x .get ("roles" , [])
144+ if role ["roleType" ].lower ().replace (" " , "_" ) == PartyRole .RoleTypes .COMPLETING_PARTY .value
145+ )
146+ ]
147+ correction_type = filing_dict .get ("filing" ).get ("correction" ).get ("type" , "STAFF" )
148+ if correction_type == "STAFF" :
149+ if len (completing_parties ) != 0 :
150+ msg .append ({
151+ "error" : "Should not provide completing party when correction type is STAFF" ,
152+ "path" : relationships_path
153+ })
154+ elif len (completing_parties ) == 0 :
155+ msg .append ({"error" : "Completing party is required." , "path" : relationships_path })
156+ elif len (completing_parties ) > 1 :
157+ msg .append ({"error" : "Only one completing party is allowed." , "path" : relationships_path })
158+
159+ if business .state == Business .State .HISTORICAL .value :
160+ _validate_corps_correction_historical (business , filing_dict , msg )
161+ else :
162+ _validate_corps_correction_active (business , filing_dict , legal_type , msg )
163+
164+
165+ def _validate_corps_correction_historical (business : Business , filing_dict , msg ):
166+ filing_type = "correction"
167+ msg .extend (_validate_out_correction (filing_dict , filing_type , business ))
168+ if relationships := filing_dict .get ("filing" , {}).get ("correction" , {}).get ("relationships" , None ):
169+ custodian_parties = [
170+ x for x in relationships
171+ if any (
172+ role for role in x .get ("roles" , [])
173+ if role ["roleType" ].lower () == PartyRole .RoleTypes .CUSTODIAN .value
174+ )
175+ ]
176+ relationships_path = "/filing/correction/relationships"
177+ if len (custodian_parties ) > 1 :
178+ msg .append ({"error" : "Only one custodian is allowed." , "path" : relationships_path })
179+ elif len (custodian_parties ) == 1 :
180+ today = datetime .now (tz = UTC ).date ()
181+ existing_custodian = PartyRole .get_party_roles (business .id , today , PartyRole .RoleTypes .CUSTODIAN .value )
182+ if not custodian_parties [0 ].get ("entity" , {}).get ("identifier" ) and len (existing_custodian ) > 0 :
183+ msg .append ({
184+ "error" : "Custodian already exists for this business, cannot create another custodian." ,
185+ "path" : relationships_path
186+ })
187+ msg .extend (
188+ validate_custodian_email (
189+ custodian_parties [0 ].get ("entity" , {}).get ("email" ),
190+ f"{ relationships_path } /entity/email"
191+ )
192+ )
193+
194+ msg .extend (validate_relationships (
195+ business ,
196+ filing_dict ,
197+ filing_type ,
198+ [
199+ PartyRole .RoleTypes .CUSTODIAN ,
200+ PartyRole .RoleTypes .COMPLETING_PARTY
201+ ],
202+ True ,
203+ True ,
204+ [PartyRole .RoleTypes .CUSTODIAN , PartyRole .RoleTypes .COMPLETING_PARTY ]
205+ ))
206+
207+
208+ def _validate_corps_correction_active (business : Business , filing_dict , legal_type , msg ):
148209 filing_type = "correction"
149210 if new_legal_type := filing_dict .get ("filing" , {}).get ("correction" , {}).get ("newLegalType" ):
150211 if business .legal_type == new_legal_type :
@@ -163,6 +224,23 @@ def _validate_corps_correction(business: Business, filing_dict, legal_type, msg)
163224 msg .extend (err )
164225 # FUTURE: this should be removed when COLIN sync back is no longer required.
165226 msg .extend (validate_parties_names (filing_dict , filing_type , legal_type ))
227+
228+ if filing_dict .get ("filing" , {}).get ("correction" , {}).get ("relationships" , None ):
229+ msg .extend (validate_relationships (
230+ business ,
231+ filing_dict ,
232+ filing_type ,
233+ [
234+ PartyRole .RoleTypes .DIRECTOR ,
235+ PartyRole .RoleTypes .LIQUIDATOR ,
236+ PartyRole .RoleTypes .RECEIVER ,
237+ PartyRole .RoleTypes .COMPLETING_PARTY
238+ ],
239+ True ,
240+ True ,
241+ [PartyRole .RoleTypes .DIRECTOR , PartyRole .RoleTypes .COMPLETING_PARTY ]
242+ ))
243+
166244 if filing_dict .get ("filing" , {}).get ("correction" , {}).get ("shareStructure" , None ):
167245 err = validate_share_structure (filing_dict , filing_type , legal_type )
168246 if err :
@@ -171,13 +249,8 @@ def _validate_corps_correction(business: Business, filing_dict, legal_type, msg)
171249 msg .extend (validate_share_currency (filing_dict , filing_type , business ))
172250 msg .extend (validate_resolution_date_in_share_structure (filing_dict , filing_type , business ))
173251
174- if filing_dict .get ("filing" , {}).get ("correction" , {}).get ("courtOrder" , None ):
175- msg .extend (court_order_validation (filing_dict ))
176-
177252 msg .extend (_validate_continuation_in_correction (filing_dict , filing_type , legal_type , business ))
178- msg .extend (_validate_out_correction (filing_dict , filing_type , business ))
179253 msg .extend (_validate_amalgamation_correction (filing_dict , filing_type , business ))
180- msg .extend (_validate_court_orders_correction (filing_dict , business ))
181254
182255
183256def _validate_court_orders_correction (filing_dict , business : Business ):
0 commit comments