Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,55 @@

from business_filer.exceptions import QueueException
from business_filer.filing_meta import FilingMeta
from business_filer.filing_processors.filing_components import create_party, create_role, update_director
from business_filer.filing_processors.filing_components import (
create_party,
create_role,
update_director,
)


def process(business: Business, filing_rec: Filing, filing_meta: FilingMeta): # noqa: PLR0912
def _update_director_using_name(director: dict, business_id: int):
"""Update director information based on name matching."""
if "nameChanged" in director["actions"]:
director_name = (director["officer"].get("prevFirstName") +
director["officer"].get("prevMiddleInitial", "") +
director["officer"].get("prevLastName"))
else:
director_name = (director["officer"].get("firstName") +
director["officer"].get("middleInitial", "") +
director["officer"].get("lastName"))
if not director_name:
current_app.logger.error("Could not resolve director name from json %s.", director)
raise QueueException

for current_director in PartyRole.get_parties_by_role(business_id, PartyRole.RoleTypes.DIRECTOR.value):
current_director_name = (current_director.party.first_name +
(current_director.party.middle_initial or "") +
current_director.party.last_name)
if current_director_name.upper() == director_name.upper() and current_director.cessation_date is None:
update_director(director=current_director, new_info=director)
break

def _update_director_using_party_id(director: dict, business_id: int):
"""Update director information based on party ID matching."""
party_id = director["officer"].get("id")
if not party_id:
current_app.logger.error("Could not resolve party id from json %s.", director)
raise QueueException

matched = False
for current_director in PartyRole.get_parties_by_role(business_id, PartyRole.RoleTypes.DIRECTOR.value):
if current_director.party_id == party_id and current_director.cessation_date is None:
update_director(director=current_director, new_info=director)
matched = True
break

if not matched:
current_app.logger.error("Could not find active director with party id %s for business %s.",
party_id, business_id)
raise QueueException

def process(business: Business, filing_rec: Filing, filing_meta: FilingMeta): # noqa: PLR0912
"""Render the change_of_directors onto the business model objects."""
filing_json = copy.deepcopy(filing_rec.filing_json)
if not (directors := filing_json["filing"]["changeOfDirectors"].get("directors")):
Expand All @@ -54,7 +99,8 @@ def process(business: Business, filing_rec: Filing, filing_meta: FilingMeta): #
new_directors = []

for director in directors: # pylint: disable=too-many-nested-blocks;
# Applies only for filings coming from colin.
# Applies to CoD filings originating from COLIN (currently COOPs only).
# Continue using name-based matching for directors.
if filing_rec.colin_event_ids:
director_found = False
director_name = (director["officer"].get("firstName") +
Expand Down Expand Up @@ -88,32 +134,16 @@ def process(business: Business, filing_rec: Filing, filing_meta: FilingMeta): #
new_directors.append(director)

elif any([action != "appointed" for action in director["actions"]]): # noqa: C419
# get name of director in json for comparison *
if "nameChanged" in director["actions"]:
director_name = (director["officer"].get("prevFirstName") +
director["officer"].get("prevMiddleInitial", "") +
director["officer"].get("prevLastName"))
if filing_rec.colin_event_ids:
# Colin path: retain name-based matching for now.
_update_director_using_name(director=director, business_id=business.id)
Copy link
Copy Markdown
Collaborator Author

@meawong meawong Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't maintain the director id from lear in colin and vice versa so keeping the existing logic for colin path (matching based on name) since there is no cross-reference for the id.

else:
director_name = (director["officer"].get("firstName") +
director["officer"].get("middleInitial", "") +
director["officer"].get("lastName"))
if not director_name:
current_app.logger.error("Could not resolve director name from json %s.", director)
raise QueueException

for current_director in PartyRole.get_parties_by_role(business.id, PartyRole.RoleTypes.DIRECTOR.value):
# get name of director in database for comparison *
current_director_name = (current_director.party.first_name +
(current_director.party.middle_initial or "") +
current_director.party.last_name)
# Update only an active director
if current_director_name.upper() == director_name.upper() and current_director.cessation_date is None:
update_director(director=current_director, new_info=director)
break
# Lear path: match by party ID instead of name
_update_director_using_party_id(director=director, business_id=business.id)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For lear-native filings, we can match by party ID instead of name.


for director in new_directors:
# add new diretor party role to the business
party = create_party(business_id=business.id, party_info=director)
party = create_party(business_id=business.id, party_info=director, create=False)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create=False is used to bypass checking for an existing matching party, this is used in flows where we are creating new directors (i.e. IA, Amalg, Registration) and should be the same for COD when we are appointing a new director

role = {
"roleType": "Director",
"appointmentDate": director.get("appointmentDate"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ def test_process_combined_filing(app, session, mocker):
directors = PartyRole.get_parties_by_role(business.id, PartyRole.RoleTypes.DIRECTOR.value)
assert len(directors) == 4
business_id = business.id
COMBINED_FILING['filing']['changeOfDirectors']['directors'][0]['officer']['id'] = director_party1.id
COMBINED_FILING['filing']['changeOfDirectors']['directors'][1]['officer']['id'] = director_party2.id
COMBINED_FILING['filing']['changeOfDirectors']['directors'][2]['officer']['id'] = director_party3.id
COMBINED_FILING['filing']['changeOfDirectors']['directors'][3]['officer']['id'] = director_party4.id

filing_id = (create_filing(payment_id, COMBINED_FILING, business.id)).id
filing_msg = FilingMessage(filing_identifier=filing_id)

Expand Down