From ac861256a230b1577507bc837a918a7f0e5c5b3d Mon Sep 17 00:00:00 2001 From: Hongjing <60866283+chenhongjing@users.noreply.github.com> Date: Tue, 13 Aug 2024 14:56:33 -0700 Subject: [PATCH] 21954 - Sync involuntary dissolutions back to COLIN (#2911) * 21954 - Sync involuntary dissolutions back to COLIN (colin-api & legal-api updates) Signed-off-by: Hongjing Chen * update to find batch_processing by filing_id Signed-off-by: Hongjing Chen --------- Signed-off-by: Hongjing Chen --- colin-api/src/colin_api/models/business.py | 2 ++ colin-api/src/colin_api/models/filing.py | 25 ++++++++++++++++++- colin-api/src/colin_api/resources/filing.py | 12 ++++++--- .../resources/v2/business/colin_sync.py | 17 ++++++++++++- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/colin-api/src/colin_api/models/business.py b/colin-api/src/colin_api/models/business.py index 6f0477d608..dc677ad3d7 100644 --- a/colin-api/src/colin_api/models/business.py +++ b/colin-api/src/colin_api/models/business.py @@ -64,6 +64,8 @@ class CorpStateTypes(Enum): VOLUNTARY_DISSOLUTION = 'HDV' ADMINISTRATIVE_DISSOLUTION = 'HDA' AMALGAMATED = 'HAM' + INVOLUNTARY_DISSOLUTION_NO_AR = 'HDF' + INVOLUNTARY_DISSOLUTION_NO_TR = 'HDT' NUMBERED_CORP_NAME_SUFFIX = { TypeCodes.BCOMP.value: 'B.C. LTD.', diff --git a/colin-api/src/colin_api/models/filing.py b/colin-api/src/colin_api/models/filing.py index 2b3a256a48..e83553bf76 100644 --- a/colin-api/src/colin_api/models/filing.py +++ b/colin-api/src/colin_api/models/filing.py @@ -155,7 +155,7 @@ class FilingSource(Enum): # `voluntaryDissolution filing type in place as unsure if it is being used in other places 'dissolution': { 'sub_type_property': 'dissolutionType', - 'sub_type_list': ['voluntary', 'administrative'], + 'sub_type_list': ['voluntary', 'administrative', 'involuntary'], 'type_code_list': ['OTVDS', 'ADVD2'], 'voluntary': { Business.TypeCodes.COOP.value: 'OTVDS', @@ -996,6 +996,29 @@ def add_administrative_dissolution_event(cls, con, corp_num) -> int: Business.CorpStateTypes.ADMINISTRATIVE_DISSOLUTION.value) return event_id + @classmethod + def add_involuntary_dissolution_event(cls, con, corp_num, filing_body) -> int: + """Add involuntary dissolution event.""" + if not (filing_meta_data := filing_body.get('metaData')): + return None + + event_type = None + corp_state = None + if filing_meta_data.get('overdueARs'): + event_type = 'SYSDF' + corp_state = Business.CorpStateTypes.INVOLUNTARY_DISSOLUTION_NO_AR.value + elif filing_meta_data.get('overdueTransition'): + event_type = 'SYSDT' + corp_state = Business.CorpStateTypes.INVOLUNTARY_DISSOLUTION_NO_TR.value + + if event_type: + cursor = con.cursor() + event_id = cls._get_event_id(cursor=cursor, corp_num=corp_num, event_type=event_type) + Business.update_corp_state(cursor, event_id, corp_num, corp_state) + return event_id + + return None + # pylint: disable=too-many-locals,too-many-statements,too-many-branches,too-many-nested-blocks; @classmethod def add_filing(cls, con, filing: Filing) -> int: diff --git a/colin-api/src/colin_api/resources/filing.py b/colin-api/src/colin_api/resources/filing.py index 1dc3fa700b..775f78120c 100644 --- a/colin-api/src/colin_api/resources/filing.py +++ b/colin-api/src/colin_api/resources/filing.py @@ -146,11 +146,17 @@ def post(legal_type, identifier, **kwargs): con.begin() # No filing will be created for administrative dissolution. Create an event and update corp state. - if ('dissolution' in filing_list and - Filing.get_filing_sub_type('dissolution', filing_list['dissolution']) == 'administrative'): + if ( + 'dissolution' in filing_list and + (filing_sub_type := Filing.get_filing_sub_type('dissolution', filing_list['dissolution'])) + in ['administrative', 'involuntary'] + ): if legal_type == Business.TypeCodes.COOP.value: raise Exception('Not implemented!') # pylint: disable=broad-exception-raised - event_id = Filing.add_administrative_dissolution_event(con, identifier) + if filing_sub_type == 'administrative': + event_id = Filing.add_administrative_dissolution_event(con, identifier) + else: + event_id = Filing.add_involuntary_dissolution_event(con, identifier, filing_list['dissolution']) con.commit() return jsonify({ 'filing': { diff --git a/legal-api/src/legal_api/resources/v2/business/colin_sync.py b/legal-api/src/legal_api/resources/v2/business/colin_sync.py index a597430de0..c422e59cb7 100644 --- a/legal-api/src/legal_api/resources/v2/business/colin_sync.py +++ b/legal-api/src/legal_api/resources/v2/business/colin_sync.py @@ -21,7 +21,16 @@ from flask_cors import cross_origin from legal_api.exceptions import BusinessException -from legal_api.models import AmalgamatingBusiness, Amalgamation, Business, Filing, PartyRole, UserRoles, db +from legal_api.models import ( + AmalgamatingBusiness, + Amalgamation, + BatchProcessing, + Business, + Filing, + PartyRole, + UserRoles, + db, +) from legal_api.models.colin_event_id import ColinEventId from legal_api.services.business_details_version import VersionedBusinessDetailsService from legal_api.utils.auth import jwt @@ -76,6 +85,12 @@ def get_completed_filings_for_colin(): except Exception as ex: # noqa: B902 current_app.logger.info(ex) continue # do not break this function because of one filing + elif (filing.filing_type == 'dissolution' and + filing.filing_sub_type == 'involuntary'): + batch_processings = BatchProcessing.find_by(filing_id=filing.id) + if not batch_processings: + continue # skip filing for missing batch processing info + filing_json['filing']['dissolution']['metaData'] = batch_processings[0].meta_data filings.append(filing_json) return jsonify({