Skip to content

Commit

Permalink
21747 sync incorporationApplication of BC, CC, ULC (#2768)
Browse files Browse the repository at this point in the history
  • Loading branch information
vysakh-menon-aot authored Jun 19, 2024
1 parent 6192b01 commit baa3e8f
Show file tree
Hide file tree
Showing 21 changed files with 164 additions and 165 deletions.
3 changes: 1 addition & 2 deletions colin-api/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ good-names=

[pylint]
ignore=migrations,test
max_line_length=120
notes=FIXME,XXX,TODO
ignored-modules=flask_sqlalchemy,sqlalchemy,SQLAlchemy,alembic,scoped_session
ignored-classes=scoped_session
min-similarity-lines=100
disable=C0301,W0511,R0801,R0902A,E1136
disable=C0301,W0511,R0801,R0902,E1136

[isort]
line_length = 120
Expand Down
2 changes: 1 addition & 1 deletion colin-api/src/colin_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import sentry_sdk # noqa: I001; pylint: disable=ungrouped-imports; conflicts with Flake8

from flask import Flask
from colin_api.services import flags
from sentry_sdk.integrations.flask import FlaskIntegration # noqa: I001

from colin_api import config, errorhandlers
from colin_api.resources import API, API_BLUEPRINT, OPS_BLUEPRINT
from colin_api.services import flags
from colin_api.utils.auth import jwt
from colin_api.utils.logging import setup_logging
from colin_api.utils.run_version import get_run_version
Expand Down
22 changes: 11 additions & 11 deletions colin-api/src/colin_api/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GenericException(Exception):

def __init__(self, error, status_code, *args, **kwargs):
"""Return a valid GenericException."""
super(GenericException, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.error = error
self.status_code = status_code

Expand All @@ -33,7 +33,7 @@ class BusinessNotFoundException(GenericException):

def __init__(self, *args, identifier=None, **kwargs):
"""Return a valid BusinessNotFoundException."""
super(BusinessNotFoundException, self).__init__(None, None, *args, **kwargs)
super().__init__(None, None, *args, **kwargs)
if identifier:
self.error = f'{identifier} not found'
else:
Expand All @@ -46,7 +46,7 @@ class FilingNotFoundException(GenericException):

def __init__(self, *args, identifier: str, filing_type: str, **kwargs):
"""Return a valid FilingNotFoundException."""
super(FilingNotFoundException, self).__init__(None, None, *args, **kwargs)
super().__init__(None, None, *args, **kwargs)
self.error = f'{filing_type} not found for {identifier}'
self.status_code = 404

Expand All @@ -56,7 +56,7 @@ class OfficeNotFoundException(GenericException):

def __init__(self, *args, identifier: str = None, **kwargs):
"""Return a valid AddressNotFoundException."""
super(OfficeNotFoundException, self).__init__(None, None, *args, **kwargs)
super().__init__(None, None, *args, **kwargs)
if identifier:
self.error = f'Office not found for {identifier}'
else:
Expand All @@ -69,7 +69,7 @@ class AddressNotFoundException(GenericException):

def __init__(self, *args, address_id, **kwargs):
"""Return a valid AddressNotFoundException."""
super(AddressNotFoundException, self).__init__(None, None, *args, **kwargs)
super().__init__(None, None, *args, **kwargs)
if address_id:
self.error = f'Address not found with id: {address_id}'
else:
Expand All @@ -82,7 +82,7 @@ class PartiesNotFoundException(GenericException):

def __init__(self, *args, identifier: str = None, **kwargs):
"""Return a valid PartiesNotFoundException."""
super(PartiesNotFoundException, self).__init__(None, None, *args, **kwargs)
super().__init__(None, None, *args, **kwargs)
if identifier:
self.error = f'Parties not found for {identifier}'
else:
Expand All @@ -94,8 +94,8 @@ class NamesNotFoundException(GenericException):
"""Exception with defined error code and messaging."""

def __init__(self, *args, identifier: str = None, **kwargs):
"""Return a valid PartiesNotFoundException."""
super(NamesNotFoundException, self).__init__(None, None, *args, **kwargs)
"""Return a valid NamesNotFoundException."""
super().__init__(None, None, *args, **kwargs)
if identifier:
self.error = f'Corp names not found for {identifier}'
else:
Expand All @@ -108,7 +108,7 @@ class InvalidFilingTypeException(GenericException):

def __init__(self, *args, filing_type=None, **kwargs):
"""Return a valid InvalidFilingTypeException."""
super(InvalidFilingTypeException, self).__init__(None, None, *args, **kwargs)
super().__init__(None, None, *args, **kwargs)
if filing_type:
self.error = f'{filing_type} is an invalid filing type'
else:
Expand All @@ -120,8 +120,8 @@ class UnableToDetermineCorpTypeException(GenericException):
"""Exception with defined error code and messaging."""

def __init__(self, *args, filing_type=None, **kwargs):
"""Return a valid InvalidFilingTypeException."""
super(UnableToDetermineCorpTypeException, self).__init__(None, None, *args, **kwargs)
"""Return a valid UnableToDetermineCorpTypeException."""
super().__init__(None, None, *args, **kwargs)
if filing_type:
self.error = f'Unable to determine corp type for {filing_type} filing type'
else:
Expand Down
6 changes: 3 additions & 3 deletions colin-api/src/colin_api/models/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def get_by_address_id(cls, cursor, address_id: str = None) -> Optional[Address]:

except Exception as err:
current_app.logger.error(err.with_traceback(None))
raise AddressNotFoundException(address_id=address_id)
raise AddressNotFoundException(address_id=address_id) # pylint: disable=raise-missing-from

@classmethod
def create_new_address(cls, cursor, address_info: dict = None, corp_num: str = None):
Expand All @@ -153,7 +153,7 @@ def create_new_address(cls, cursor, address_info: dict = None, corp_num: str = N
UPDATE system_id
SET id_num = :new_num
WHERE id_typ_cd = 'ADD'
""", new_num=addr_id+1)
""", new_num=addr_id + 1)

country_typ_cd = pycountry.countries.search_fuzzy(address_info.get('addressCountry'))[0].alpha_2
except Exception as err:
Expand Down Expand Up @@ -225,7 +225,7 @@ def delete(cls, cursor, address_ids: list = None):

if cursor.rowcount < 1:
current_app.logger.error('Database not updated.')
raise Exception
raise Exception # pylint: disable=broad-exception-raised
return
except Exception as err:
current_app.logger.error(f'Failed to delete addresses {address_ids}')
Expand Down
84 changes: 42 additions & 42 deletions colin-api/src/colin_api/models/business.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,22 @@
from colin_api.utils import convert_to_json_date, convert_to_json_datetime, convert_to_pacific_time, stringify_list


class Business: # pylint: disable=too-many-instance-attributes
class Business: # pylint: disable=too-many-instance-attributes, too-many-public-methods
"""Class to contain all model-like functions for the corporation and related tables."""

class LearBusinessTypes(Enum):
"""Temp class for lear business types, will be importing these from lear after upgrading python inage to 3.8."""

COOP = 'CP'
BCOMP = 'BEN'
BC_COMP = 'BC'
EXTRA_PRO_A = 'A'
CONTINUE_IN = 'C'


class TypeCodes(Enum):
"""Render an Enum of the Corporation Type Codes."""

EXTRA_PRO_A = 'A'
COOP = 'CP'
BCOMP = 'BEN'
BC_COMP = 'BC'
ULC_COMP = 'ULC'
CCC_COMP = 'CC'
BCOMP_CONTINUE_IN = 'CBEN'
CONTINUE_IN = 'C'
CCC_CONTINUE_IN = 'CCC'
ULC_CONTINUE_IN = 'CUL'

class CorpFrozenTypes(Enum):
"""Render an Enum of the Corporation Frozen Type Codes.
Expand All @@ -69,27 +64,19 @@ class CorpStateTypes(Enum):
VOLUNTARY_DISSOLUTION = 'HDV'
ADMINISTRATIVE_DISSOLUTION = 'HDA'

# temp converter because legal doesn't have codes only class (legal_type)
CORP_TYPE_CONVERSION = {
LearBusinessTypes.COOP.value: [
TypeCodes.COOP.value
],
LearBusinessTypes.BCOMP.value: [
TypeCodes.BCOMP.value,
TypeCodes.BC_COMP.value,
TypeCodes.ULC_COMP.value
],
LearBusinessTypes.BC_COMP.value: [
TypeCodes.BCOMP.value,
TypeCodes.BC_COMP.value,
TypeCodes.ULC_COMP.value,
TypeCodes.CCC_COMP.value
],
LearBusinessTypes.EXTRA_PRO_A.value: [
TypeCodes.EXTRA_PRO_A.value
],
NUMBERED_CORP_NAME_SUFFIX = {
TypeCodes.BCOMP: 'B.C. LTD.',
TypeCodes.BC_COMP: 'B.C. LTD.',
TypeCodes.ULC_COMP: 'B.C. UNLIMITED LIABILITY COMPANY',
TypeCodes.CCC_COMP: 'B.C. COMMUNITY CONTRIBUTION COMPANY LTD.',
}

# CORPS Continuation In has the same suffix
NUMBERED_CORP_NAME_SUFFIX[TypeCodes.BCOMP_CONTINUE_IN] = NUMBERED_CORP_NAME_SUFFIX[TypeCodes.BCOMP]
NUMBERED_CORP_NAME_SUFFIX[TypeCodes.CONTINUE_IN] = NUMBERED_CORP_NAME_SUFFIX[TypeCodes.BC_COMP]
NUMBERED_CORP_NAME_SUFFIX[TypeCodes.ULC_CONTINUE_IN] = NUMBERED_CORP_NAME_SUFFIX[TypeCodes.ULC_COMP]
NUMBERED_CORP_NAME_SUFFIX[TypeCodes.CCC_CONTINUE_IN] = NUMBERED_CORP_NAME_SUFFIX[TypeCodes.CCC_COMP]

business_number = None
corp_name = None
corp_num = None
Expand Down Expand Up @@ -154,6 +141,19 @@ def as_slim_dict(self) -> Dict:
}
}

@classmethod
def get_colin_identifier(cls, lear_identifier, legal_type):
"""Convert identifier from lear to colin."""
if legal_type in [
cls.TypeCodes.BCOMP.value,
cls.TypeCodes.BC_COMP.value,
cls.TypeCodes.ULC_COMP.value,
cls.TypeCodes.CCC_COMP.value
]:
return lear_identifier[-7:]

return lear_identifier

@classmethod
def _get_bn_15s(cls, cursor, identifiers: List) -> Dict:
"""Return a dict of idenifiers mapping to their bn_15 numbers."""
Expand Down Expand Up @@ -186,8 +186,8 @@ def _get_last_ar_dates_for_reset(cls, cursor, event_info: List, event_ids: List)
events_by_corp_num = {}
for info in event_info:
if info['filing_typ_cd'] not in ['OTINC', 'BEINC'] and \
(info['corp_num'] not in events_by_corp_num or
events_by_corp_num[info['corp_num']] > info['event_id']):
(info['corp_num'] not in events_by_corp_num or
events_by_corp_num[info['corp_num']] > info['event_id']):
events_by_corp_num[info['corp_num']] = info['event_id']

dates_by_corp_num = []
Expand Down Expand Up @@ -225,7 +225,10 @@ def _get_last_ar_dates_for_reset(cls, cursor, event_info: List, event_ids: List)
return dates_by_corp_num

@classmethod
def find_by_identifier(cls, identifier: str, corp_types: List = None, con=None) -> Business:
def find_by_identifier(cls, # pylint: disable=too-many-statements
identifier: str,
corp_types: List = None,
con=None) -> Business:
"""Return a Business by identifier."""
business = None
try:
Expand Down Expand Up @@ -270,7 +273,7 @@ def find_by_identifier(cls, identifier: str, corp_types: List = None, con=None)
assumed_name = None
corp_name = None
for name_obj in corp_names:
if name_obj.type_code == CorpName.TypeCodes.ASSUMED.value:
if name_obj.type_code == CorpName.TypeCodes.ASSUMED.value: # pylint: disable=no-else-break
assumed_name = name_obj.corp_name
break
elif name_obj.type_code in [CorpName.TypeCodes.CORP.value, CorpName.TypeCodes.NUMBERED_CORP.value]:
Expand Down Expand Up @@ -336,11 +339,8 @@ def create_corporation(cls, con, filing_info: Dict):
business.corp_num = filing_info['business']['identifier']
business.founding_date = convert_to_pacific_time(filing_info['header']['learEffectiveDate'])

if filing_info['business']['legalType'] in cls.CORP_TYPE_CONVERSION[cls.LearBusinessTypes.BCOMP.value]:
business.corp_num = business.corp_num[-7:]
business.corp_type = Business.TypeCodes.BCOMP.value
else:
business.corp_type = Business.TypeCodes.COOP.value
business.corp_type = filing_info['business']['legalType']
business.corp_num = cls.get_colin_identifier(business.corp_num, business.corp_type)

cursor = con.cursor()

Expand Down Expand Up @@ -563,7 +563,7 @@ def update_corp_type(cls, cursor, corp_num: str, corp_type: str):
try:
if corp_type not in [x.value for x in Business.TypeCodes.__members__.values()]:
current_app.logger.error(f'Tried to update {corp_num} with invalid corp type code {corp_type}')
raise Exception
raise Exception # pylint: disable=broad-exception-raised

cursor.execute(
"""
Expand Down Expand Up @@ -640,11 +640,11 @@ def get_next_corp_num(cls, con, corp_type: str) -> str:
SET id_num = :new_num
WHERE id_typ_cd = :corp_type
""",
new_num=corp_num[0]+1,
new_num=corp_num[0] + 1,
corp_type=corp_type
)

return '%07d' % corp_num
return '%07d' % corp_num # pylint: disable=consider-using-f-string
except Exception as err:
current_app.logger.error('Error looking up corp_num')
raise err
Expand Down
13 changes: 13 additions & 0 deletions colin-api/src/colin_api/models/corp_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,16 @@ def get_current_by_type(cls, cursor, corp_num: str, type_code: str) -> List:
except Exception as err:
current_app.logger.error(f'error getting current corp names by type {type_code} for {corp_num}')
raise err

@classmethod
def get_current_name_or_numbered(cls, cursor, corp_num: str) -> List:
"""Get current entity name by type code name/numbered."""
try:
querystring = cls.NAME_QUERY + " and corp_name_typ_cd in ('CO','NB') and end_event_id is null"
cursor.execute(querystring, corp_num=corp_num)
names = cls._create_name_objs(cursor=cursor)
return names[0] if names else None

except Exception as err:
current_app.logger.error(f'error getting current corp name by type name/numbered for {corp_num}')
raise err
8 changes: 4 additions & 4 deletions colin-api/src/colin_api/models/corp_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ def group_parties(cls, parties: List['Party'], completing_parties: dict) -> List
role_dict = {v: k for k, v in cls.role_types.items()} # Used as a lookup for role names

grouped_list = []
role_func = (lambda x: x.officer['firstName'] + x.officer['middleInitial'] + x.officer['lastName']
+ x.officer['orgName']) # noqa: E731;
role_func = (lambda x: # pylint: disable=unnecessary-lambda-assignment; # noqa: E731;
x.officer['firstName'] + x.officer['middleInitial'] + x.officer['lastName'] + x.officer['orgName'])

# CORP_PARTIES are stored as a separate row per Role, and need to be grouped to return a list of
# Role(s) within each Party object. First the rows are grouped in-memory by party/organization name
Expand Down Expand Up @@ -239,7 +239,7 @@ def get_all_parties(cls, cursor, corp_num: str) -> List[Party]:
party.appointment_date = party.get_start_event_date(cursor)

# only return the top level parent records
for party_id in party_id_map:
for party_id in party_id_map: # pylint: disable=consider-using-dict-items
if party_id not in child_party_ids:
party = party_id_map[party_id]
if party.appointment_date == 'unknown':
Expand Down Expand Up @@ -480,7 +480,7 @@ def create_new_corp_party(cls, cursor, event_id: int, party: Dict, business: Dic
UPDATE system_id
SET id_num = :new_num
WHERE id_typ_cd = 'CP'
""", new_num=corp_party_id+1)
""", new_num=corp_party_id + 1)

except Exception as err:
current_app.logger.error('Error in corp_party: Failed to get next corp_party_id.')
Expand Down
Loading

0 comments on commit baa3e8f

Please sign in to comment.