Skip to content

Commit

Permalink
lint fixes on filer
Browse files Browse the repository at this point in the history
  • Loading branch information
JazzarKarim committed Mar 19, 2024
1 parent 9a211ce commit 048d0f1
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from legal_api.models import (
AmalgamatingBusiness,
Amalgamation,
LegalEntity,
Filing,
LegalEntity,
OfficeType,
PartyRole,
RegistrationBootstrap,
Expand All @@ -33,11 +33,11 @@

from entity_filer.filing_meta import FilingMeta
from entity_filer.filing_processors.filing_components import (
JSON_ROLE_CONVERTER,
aliases,
business_info,
business_profile,
filings,
JSON_ROLE_CONVERTER,
shares,
)
from entity_filer.filing_processors.filing_components.offices import update_offices
Expand Down Expand Up @@ -125,10 +125,12 @@ def dissolve_amalgamating_business(business: LegalEntity, filing_rec: Filing):
db.session.add(business)


def process(business: LegalEntity, # pylint: disable=too-many-branches, too-many-locals
filing: Dict,
filing_rec: Filing,
filing_meta: FilingMeta):
def process(
business: LegalEntity, # pylint: disable=too-many-branches, too-many-locals
filing: Dict,
filing_rec: Filing,
filing_meta: FilingMeta,
):
"""Process the incoming amalgamation application filing."""
# Extract the filing information for amalgamation
amalgamation_filing = filing.get("filing", {}).get("amalgamationApplication")
Expand Down Expand Up @@ -159,7 +161,7 @@ def process(business: LegalEntity, # pylint: disable=too-many-branches, too-man
business.state = LegalEntity.State.ACTIVE

amalgamation.filing_id = filing_rec.id
amalgamation_type = amalgamation_filing.get('type')
amalgamation_type = amalgamation_filing.get("type")
amalgamation.amalgamation_type = amalgamation_type
amalgamation.amalgamation_date = filing_rec.effective_date
amalgamation.court_approval = bool(amalgamation_filing.get("courtApproval"))
Expand All @@ -175,19 +177,23 @@ def process(business: LegalEntity, # pylint: disable=too-many-branches, too-man
if not business:
raise DefaultException(f"amalgamationApplication {filing_rec.id}, Unable to create business.")

if amalgamation_type in [Amalgamation.AmalgamationTypes.horizontal.name,
Amalgamation.AmalgamationTypes.vertical.name]:
if amalgamation_type in [
Amalgamation.AmalgamationTypes.horizontal.name,
Amalgamation.AmalgamationTypes.vertical.name,
]:
# Include/Replace director, office and shares by finding holding or primary business (won't be a foreign)
amalgamating_business = next(x for x in amalgamation.amalgamating_businesses
if x.role in [AmalgamatingBusiness.Role.holding.name,
AmalgamatingBusiness.Role.primary.name])
amalgamating_business = next(
x
for x in amalgamation.amalgamating_businesses
if x.role in [AmalgamatingBusiness.Role.holding.name, AmalgamatingBusiness.Role.primary.name]
)
primary_or_holding_business = LegalEntity.find_by_internal_id(amalgamating_business.business_id)

_set_parties(primary_or_holding_business, filing_rec, amalgamation_filing)
_set_offices(primary_or_holding_business, amalgamation_filing)
_set_shares(primary_or_holding_business, amalgamation_filing)

if offices := amalgamation_filing.get('offices'):
if offices := amalgamation_filing.get("offices"):
update_offices(business, offices)

if parties := amalgamation_filing.get("parties"):
Expand Down Expand Up @@ -215,38 +221,39 @@ def process(business: LegalEntity, # pylint: disable=too-many-branches, too-man

def _set_parties(primary_or_holding_business, filing_rec, amalgamation_filing):
parties = []
active_directors = PartyRole.get_active_directors(primary_or_holding_business.id,
filing_rec.effective_date.date())
active_directors = PartyRole.get_active_directors(primary_or_holding_business.id, filing_rec.effective_date.date())
# copy director
for director in active_directors:
director_json = director.json
director_json['roles'] = [{
'roleType': 'Director',
'appointmentDate': filing_rec.effective_date.isoformat()
}]
director_json["roles"] = [{"roleType": "Director", "appointmentDate": filing_rec.effective_date.isoformat()}]

# cleanup director json
del director_json['officer']['id']
del director_json['role']
del director_json['appointmentDate']
if 'cessationDate' in director_json:
del director_json['cessationDate']
if 'deliveryAddress' in director_json:
del director_json['deliveryAddress']['id']
if 'mailingAddress' in director_json:
del director_json['mailingAddress']['id']
del director_json["officer"]["id"]
del director_json["role"]
del director_json["appointmentDate"]
if "cessationDate" in director_json:
del director_json["cessationDate"]
if "deliveryAddress" in director_json:
del director_json["deliveryAddress"]["id"]
if "mailingAddress" in director_json:
del director_json["mailingAddress"]["id"]

parties.append(director_json)

# copy completing party from filing json
for party_info in amalgamation_filing.get('parties'):
if comp_party_role := next((x for x in party_info.get('roles')
if JSON_ROLE_CONVERTER.get(x['roleType'].lower(), '')
== PartyRole.RoleTypes.COMPLETING_PARTY.value), None):
party_info['roles'] = [comp_party_role] # override roles to have only completing party
for party_info in amalgamation_filing.get("parties"):
if comp_party_role := next(
(
x
for x in party_info.get("roles")
if JSON_ROLE_CONVERTER.get(x["roleType"].lower(), "") == PartyRole.RoleTypes.COMPLETING_PARTY.value
),
None,
):
party_info["roles"] = [comp_party_role] # override roles to have only completing party
parties.append(party_info)
break
amalgamation_filing['parties'] = parties
amalgamation_filing["parties"] = parties


def _set_offices(primary_or_holding_business, amalgamation_filing):
Expand All @@ -258,21 +265,21 @@ def _set_offices(primary_or_holding_business, amalgamation_filing):
offices[i.office_type] = {}
for address in i.addresses:
address_json = address.json
del address_json['id']
offices[i.office_type][f'{address.address_type}Address'] = address_json
amalgamation_filing['offices'] = offices
del address_json["id"]
offices[i.office_type][f"{address.address_type}Address"] = address_json
amalgamation_filing["offices"] = offices


def _set_shares(primary_or_holding_business, amalgamation_filing):
# copy shares
share_classes = []
for share_class in primary_or_holding_business.share_classes.all():
share_class_json = share_class.json
del share_class_json['id']
for series in share_class_json.get('series', []):
del series['id']
del share_class_json["id"]
for series in share_class_json.get("series", []):
del series["id"]
share_classes.append(share_class_json)
amalgamation_filing['shareStructure'] = {'shareClasses': share_classes}
amalgamation_filing["shareStructure"] = {"shareClasses": share_classes}


def post_process(business: LegalEntity, filing: Filing):
Expand Down
16 changes: 8 additions & 8 deletions queue_services/entity-filer/tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
from contextlib import contextmanager

import sqlalchemy
from freezegun import freeze_time
from legal_api.models import Filing, ShareClass, ShareSeries, db
from legal_api.models.colin_event_id import ColinEventId

from entity_filer.utils.datetime import datetime, timezone
from freezegun import freeze_time
from tests import EPOCH_DATETIME, FROZEN_DATETIME
from legal_api.models import db, Filing, ShareClass, ShareSeries
from legal_api.models.colin_event_id import ColinEventId

AR_FILING = {
"filing": {
Expand Down Expand Up @@ -570,24 +570,24 @@ def create_share_class(business, no_of_shares=1, no_of_series_in_each_share=2):
"""Create a new share class and associated series."""
for i in range(no_of_shares):
share_class = ShareClass(
name=f'{business.identifier} Share Class {i}',
name=f"{business.identifier} Share Class {i}",
priority=1,
max_share_flag=True,
max_shares=100,
par_value_flag=True,
par_value=10,
currency='CAD',
special_rights_flag=False
currency="CAD",
special_rights_flag=False,
)

share_class.series = []
for j in range(no_of_series_in_each_share):
share_series = ShareSeries(
name=f'{business.identifier} Share {i} Series {j}',
name=f"{business.identifier} Share {i} Series {j}",
priority=1,
max_share_flag=True,
max_shares=50,
special_rights_flag=False
special_rights_flag=False,
)
share_class.series.append(share_series)

Expand Down
Loading

0 comments on commit 048d0f1

Please sign in to comment.