diff --git a/colin-api/src/colin_api/models/filing.py b/colin-api/src/colin_api/models/filing.py index f1cd5005df..3f751643d2 100644 --- a/colin-api/src/colin_api/models/filing.py +++ b/colin-api/src/colin_api/models/filing.py @@ -112,11 +112,17 @@ class FilingSource(Enum): Business.TypeCodes.CCC_COMP.value: 'CONVL' }, 'alteration': { - 'type_code_list': ['NOALA', 'NOALR'], - Business.TypeCodes.BCOMP.value: 'NOALR', + 'type_code_list': ['NOABE', 'NOALE', 'NOALR', 'NOALD', 'NOALA', 'NOALB', 'NOALU', 'NOALC'], + Business.TypeCodes.BCOMP.value: 'NOABE', + 'BC_TO_BEN': 'NOALE', + 'BEN_TO_BC': 'NOALR', + 'ULC_TO_BEN': 'NOALD', Business.TypeCodes.BC_COMP.value: 'NOALA', Business.TypeCodes.ULC_COMP.value: 'NOALA', - Business.TypeCodes.CCC_COMP.value: 'NOALA' + Business.TypeCodes.CCC_COMP.value: 'NOALA', + 'ULC_TO_BC': 'NOALB', + 'BC_TO_ULC': 'NOALU', + 'BC_TO_CC': 'NOALC', }, 'correction': { 'type_code_list': ['CRBIN'], @@ -287,13 +293,20 @@ def get_email(self) -> str: return self.body['contactPoint']['email'] return self.header.get('email', '') - def get_filing_type_code(self, filing_sub_type: str = None) -> Optional[str]: + def get_filing_type_code(self) -> Optional[str]: """Get filing type code.""" - sub_type = filing_sub_type or self.filing_sub_type - if sub_type: - return Filing.FILING_TYPES.get(self.filing_type, {})\ - .get(self.filing_sub_type, {})\ - .get(self.business.corp_type, None) + if self.filing_type == 'alteration': + corp_type_change = self.business.corp_type + if ((to_type := self.body.get('business', {}).get('legalType')) and + to_type != self.business.corp_type): + corp_type_change = f'{self.business.corp_type}_TO_{to_type}' + return Filing.FILING_TYPES.get(self.filing_type, {}).get(corp_type_change, None) + + if self.filing_sub_type: + return (Filing.FILING_TYPES.get(self.filing_type, {}) + .get(self.filing_sub_type, {}) + .get(self.business.corp_type, None)) + return Filing.FILING_TYPES.get(self.filing_type, {}).get(self.business.corp_type, None) def as_dict(self) -> Dict: @@ -476,7 +489,7 @@ def _insert_filing(cls, cursor, filing, ar_date: str, agm_date: str): # pylint: 'AMLHB', 'AMALH', 'AMLHU', 'AMLHC', 'AMLVB', 'AMALV', 'AMLVU', 'AMLVC', 'CONTB', 'CONTI', 'CONTU', 'CONTC', - 'NOALA', 'NOALB', 'NOALC', 'NOALE', 'NOALR', 'NOALU', + 'NOABE', 'NOALE', 'NOALR', 'NOALD', 'NOALA', 'NOALB', 'NOALU', 'NOALC' 'REGSN', 'REGSO', 'COURT']: arrangement_ind = 'N' court_order_num = None @@ -811,12 +824,16 @@ def get_filing(cls, filing: Filing, con=None, year: int = None) -> Dict: # should only ever be 1 active name for any given event break - if 'business' in components and schema_name != 'continuation_in': + if 'business' in components and schema_name == 'alteration': filing.body['business'] = {} - if filing_event_info['filing_type_code'] == 'NOALR': + if filing_event_info['filing_type_code'] in ['NOALR', 'NOALB']: filing.body['business']['legalType'] = Business.TypeCodes.BC_COMP.value - elif filing_event_info['filing_type_code'] == 'NOALE': + elif filing_event_info['filing_type_code'] in ['NOALE', 'NOALD', 'NOABE']: filing.body['business']['legalType'] = Business.TypeCodes.BCOMP.value + elif filing_event_info['filing_type_code'] == 'NOALU': + filing.body['business']['legalType'] = Business.TypeCodes.ULC_COMP.value + elif filing_event_info['filing_type_code'] == 'NOALC': + filing.body['business']['legalType'] = Business.TypeCodes.CCC_COMP.value elif filing_event_info['filing_type_code'] == 'NOALA': corp_type = cls._get_corp_type_for_event(corp_num=corp_num, event_id=filing_event_info['event_id'], @@ -827,7 +844,10 @@ def get_filing(cls, filing: Filing, con=None, year: int = None) -> Dict: raise UnableToDetermineCorpTypeException(filing_type=filing.filing_type) else: raise InvalidFilingTypeException(filing_type=filing_event_info['filing_type_code']) - filing.body['business']['identifier'] = f'BC{filing.business.corp_num}' + if filing.business.corp_num.isdecimal(): # valid only for BC + filing.body['business']['identifier'] = f'BC{filing.business.corp_num}' + else: + filing.body['business']['identifier'] = filing.business.corp_num if 'provisionsRemoved' in components: provisions = Business.get_corp_restriction( @@ -1149,12 +1169,18 @@ def add_filing(cls, con, filing: Filing) -> int: cursor=cursor, corp_num=corp_num, date=agm_date, annual_report=is_annual_report, last_ar_filed_dt=last_ar_filed_dt) - # Freeze BEN entity - if (filing.filing_type == 'alteration' or - (filing.filing_type in ['incorporationApplication', 'amalgamationApplication'] and - business['business']['legalType'] == Business.TypeCodes.BCOMP.value) or - (filing.filing_type == 'continuationIn' and - business['business']['legalType'] == Business.TypeCodes.BCOMP_CONTINUE_IN.value)): + is_new_ben = (filing.filing_type in ['incorporationApplication', 'amalgamationApplication'] and + business['business']['legalType'] == Business.TypeCodes.BCOMP.value) + is_new_cben = (filing.filing_type == 'continuationIn' and + business['business']['legalType'] == Business.TypeCodes.BCOMP_CONTINUE_IN.value) + is_alteration_to_ben_or_cben = (filing.filing_type == 'alteration' and + filing.body.get('business', {}).get('legalType') in [ + Business.TypeCodes.BCOMP.value, + Business.TypeCodes.BCOMP_CONTINUE_IN.value, + ]) + + # Freeze BEN/CBEN entity + if (is_new_ben or is_new_cben or is_alteration_to_ben_or_cben): Business.update_corp_frozen_type(cursor, corp_num, Business.CorpFrozenTypes.COMPANY_FROZEN.value) return filing.event_id @@ -1390,15 +1416,19 @@ def _process_directors(cls, cursor, filing: Filing, business: Business, corp_num @classmethod def _create_corp_name(cls, cursor, filing: Filing, corp_num: str, name: str = None): """Create name.""" + if not name and filing.filing_type != 'correction': + name = filing.body.get('nameRequest', {}).get('legalName', None) + if filing.filing_type in ['amalgamationApplication', 'continuationIn', 'incorporationApplication']: # create corp state Business.create_corp_state(cursor=cursor, corp_num=corp_num, event_id=filing.event_id) elif filing.filing_type == 'alteration': - # end old - CorpName.end_current(cursor=cursor, event_id=filing.event_id, corp_num=corp_num) - - if not name and filing.filing_type != 'correction': - name = filing.body.get('nameRequest', {}).get('legalName', None) + old_corp_name = CorpName.get_current_name_or_numbered(cursor=cursor, corp_num=corp_num) + if old_corp_name.corp_name != name: + # end old corp name + CorpName.end_current(cursor=cursor, event_id=filing.event_id, corp_num=corp_num) + else: + return # No change corp_name_obj = CorpName() corp_name_obj.corp_num = corp_num diff --git a/queue_services/entity-filer/src/entity_filer/filing_processors/alteration.py b/queue_services/entity-filer/src/entity_filer/filing_processors/alteration.py index ce41170b56..a9038fca84 100644 --- a/queue_services/entity-filer/src/entity_filer/filing_processors/alteration.py +++ b/queue_services/entity-filer/src/entity_filer/filing_processors/alteration.py @@ -43,15 +43,17 @@ def process( alteration_json = dpath.util.get(filing, '/alteration') coop_association_type = alteration_json.get('cooperativeAssociationType') filing_meta.alteration = {**filing_meta.alteration, - **{'fromCooperativeAssociationType': business.association_type, - 'toCooperativeAssociationType': coop_association_type}} + 'fromCooperativeAssociationType': business.association_type, + 'toCooperativeAssociationType': coop_association_type} business_info.set_association_type(business, coop_association_type) else: business_json = dpath.util.get(filing, '/alteration/business') - filing_meta.alteration = {**filing_meta.alteration, - **{'fromLegalType': business.legal_type, - 'toLegalType': business_json.get('legalType')}} - business_info.set_corp_type(business, business_json) + to_legal_type = business_json.get('legalType') + if business.legal_type != to_legal_type: + filing_meta.alteration = {**filing_meta.alteration, + 'fromLegalType': business.legal_type, + 'toLegalType': to_legal_type} + business_info.set_corp_type(business, business_json) # Alter the business name, if any with suppress(IndexError, KeyError, TypeError): @@ -62,8 +64,8 @@ def process( business_info.set_legal_name(business.identifier, business, business_json) if from_legal_name != business.legal_name: filing_meta.alteration = {**filing_meta.alteration, - **{'fromLegalName': from_legal_name, - 'toLegalName': business.legal_name}} + 'fromLegalName': from_legal_name, + 'toLegalName': business.legal_name} # update court order, if any is present with suppress(IndexError, KeyError, TypeError): @@ -93,7 +95,7 @@ def process( if rules_file_key: rules_and_memorandum.update_rules(business, filing_submission, rules_file_key, rules_file_name) filing_meta.alteration = {**filing_meta.alteration, - **{'uploadNewRules': True}} + 'uploadNewRules': True} with suppress(IndexError, KeyError, TypeError): memorandum_file_key = dpath.util.get(filing, '/alteration/memorandumFileKey')