Skip to content

Commit

Permalink
24395-24396-24397 party sync fixes (bcgov#3075)
Browse files Browse the repository at this point in the history
  • Loading branch information
vysakh-menon-aot authored Nov 14, 2024
1 parent ac70149 commit debbff3
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions colin-api/src/colin_api/models/corp_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _parse_officer(cls, row):
'firstName': (row.get('first_nme', '') or '').strip(),
'lastName': (row.get('last_nme', '') or '').strip(),
'middleInitial': (row.get('middle_nme', '') or '').strip(),
'orgName': (row.get('business_nme', '') or '').strip()
'organizationName': (row.get('business_nme', '') or '').strip()
}
return officer_obj

Expand Down Expand Up @@ -165,7 +165,10 @@ def group_parties(cls, parties: List['Party'], completing_parties: dict) -> List

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

# 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 @@ -395,14 +398,14 @@ def end_director_by_name(cls, cursor, director: Dict, event_id: int, corp_num: s
)
try:
officer = director['officer']
if officer.get('orgName'):
if officer.get('organizationName'):
query = query + ' and upper(trim(business_nme))=upper(:business_name)'
cursor.execute(
query,
event_id=event_id,
cessation_date=director.get('cessationDate', ''),
corp_num=corp_num,
business_name=officer['orgName']
business_name=officer['organizationName']
)
else:
query = query + \
Expand All @@ -412,7 +415,9 @@ def end_director_by_name(cls, cursor, director: Dict, event_id: int, corp_num: s
"""
first_name = officer.get('prevFirstName') or officer.get('firstName')
last_name = officer.get('prevLastName') or officer.get('lastName')
middle_initial = officer.get('prevMiddleInitial') or officer.get('middleInitial')
middle_initial = (officer.get('prevMiddleInitial') or
officer.get('middleInitial') or
officer.get('middleName'))

cursor.execute(
query,
Expand Down Expand Up @@ -481,7 +486,8 @@ def create_new_corp_party(cls, cursor, event_id: int, party: Dict, business: Dic
event_id=party['prev_event_id'],
mailing_addr_id=mailing_addr_id,
last_nme=party['officer'].get('lastName', ''),
middle_nme=party['officer'].get('middleInitial', ''),
middle_nme=(party['officer'].get('middleInitial') or
party['officer'].get('middleName')) or '',
first_nme=party['officer'].get('firstName', ''),
email=party['officer'].get('email', '')
)
Expand All @@ -491,7 +497,8 @@ def create_new_corp_party(cls, cursor, event_id: int, party: Dict, business: Dic
event_id=event_id,
mailing_addr_id=mailing_addr_id,
last_nme=party['officer'].get('lastName', ''),
middle_nme=party['officer'].get('middleInitial', ''),
middle_nme=(party['officer'].get('middleInitial') or
party['officer'].get('middleName')) or '',
first_nme=party['officer'].get('firstName', ''),
email=party['officer'].get('email', '')
)
Expand Down Expand Up @@ -542,10 +549,11 @@ def create_new_corp_party(cls, cursor, event_id: int, party: Dict, business: Dic
str(datetime.datetime.strptime(party['officeNotificationDt'], date_format))[:10]
if party.get('officeNotificationDt') else None),
last_nme=party['officer'].get('lastName', ''),
middle_nme=party['officer'].get('middleInitial', ''),
middle_nme=(party['officer'].get('middleInitial') or
party['officer'].get('middleName')) or '',
first_nme=party['officer'].get('firstName', ''),
bus_company_num=business['business'].get('businessNumber', None),
business_name=party['officer'].get('orgName', ''),
bus_company_num=None,
business_name=party['officer'].get('organizationName', ''),
prev_party_id=party['prev_id']
)
else:
Expand All @@ -569,10 +577,11 @@ def create_new_corp_party(cls, cursor, event_id: int, party: Dict, business: Dic
str(datetime.datetime.strptime(party['officeNotificationDt'], date_format))[:10]
if party.get('officeNotificationDt') else None),
last_nme=party['officer'].get('lastName', ''),
middle_nme=party['officer'].get('middleInitial', ''),
middle_nme=(party['officer'].get('middleInitial') or
party['officer'].get('middleName')) or '',
first_nme=party['officer'].get('firstName', ''),
bus_company_num=business['business'].get('businessNumber', None),
business_name=party['officer'].get('orgName', '')
bus_company_num=None,
business_name=party['officer'].get('organizationName', '')
)

except Exception as err:
Expand All @@ -582,20 +591,22 @@ def create_new_corp_party(cls, cursor, event_id: int, party: Dict, business: Dic
@classmethod
def compare_parties(cls, party: Party, officer_json: Dict):
"""Compare corp party with json, return true if their names are equal."""
if officer_json.get('prevFirstName') or officer_json.get('prevLastName') or officer_json.get('prevOrgName'):
if (officer_json.get('prevFirstName') or
officer_json.get('prevLastName') or
officer_json.get('prevOrganizationName')):
first_name = (officer_json.get('prevFirstName') or '')
middle_name = (officer_json.get('prevMiddleInitial') or '')
last_name = (officer_json.get('prevLastName') or '')
org_name = (officer_json.get('prevOrgName') or '')
org_name = (officer_json.get('prevOrganizationName') or '')
else:
first_name = (officer_json.get('firstName') or '')
middle_name = (officer_json.get('middleInitial') or '')
last_name = (officer_json.get('lastName') or '')
org_name = (officer_json.get('orgName') or '')
org_name = (officer_json.get('organizationName') or '')
if ((party.officer.get('firstName') or '').strip().upper() == first_name.strip().upper() and
(party.officer.get('middleInitial') or '').strip().upper() == middle_name.strip().upper() and
(party.officer.get('lastName') or '').strip().upper() == last_name.strip().upper() and
(party.officer.get('orgName') or '').strip().upper() == org_name.strip().upper()):
(party.officer.get('organizationName') or '').strip().upper() == org_name.strip().upper()):
return True
return False

Expand Down

0 comments on commit debbff3

Please sign in to comment.