Skip to content

Commit

Permalink
Fix debtor search empty string middle name exact match.
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Lovett <[email protected]>
  • Loading branch information
doug-lovett committed Mar 26, 2024
1 parent 4ecaf26 commit 5e4c785
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
12 changes: 6 additions & 6 deletions ppr-api/src/ppr_api/models/party.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,28 +214,28 @@ def create_from_json(json_data, party_type: str, registration_id: int = None):
party = Party()
if party_type != model_utils.PARTY_DEBTOR_BUS:
party.party_type = party_type
elif 'businessName' in json_data:
elif json_data.get('businessName'):
party.party_type = party_type
else:
party.party_type = model_utils.PARTY_DEBTOR_IND

if party_type != model_utils.PARTY_DEBTOR_BUS and 'code' in json_data:
if party_type != model_utils.PARTY_DEBTOR_BUS and json_data.get('code'):
party.branch_id = int(json_data['code'])
else:
if party_type == model_utils.PARTY_DEBTOR_BUS and 'birthDate' in json_data:
if party_type == model_utils.PARTY_DEBTOR_BUS and json_data.get('birthDate'):
party.birth_date = model_utils.ts_from_date_iso_format(json_data['birthDate'])
if 'businessName' in json_data:
if json_data.get('businessName'):
party.business_name = json_data['businessName'].strip().upper()
else:
party.last_name = json_data['personName']['last'].strip().upper()
party.first_name = json_data['personName']['first'].strip().upper()
party.first_name_char1 = party.first_name[0:1]
if len(party.first_name) > 1:
party.first_name_char2 = party.first_name[1:2]
if 'middle' in json_data['personName']:
if json_data['personName'].get('middle'):
party.middle_initial = json_data['personName']['middle'].strip().upper()

if 'emailAddress' in json_data:
if json_data.get('emailAddress'):
party.email_id = json_data['emailAddress']

party.address = Address.create_from_json(json_data['address'])
Expand Down
2 changes: 1 addition & 1 deletion ppr-api/src/ppr_api/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
Development release segment: .devN
"""

__version__ = '1.2.2' # pylint: disable=invalid-name
__version__ = '1.2.3' # pylint: disable=invalid-name
8 changes: 7 additions & 1 deletion ppr-api/tests/unit/models/test_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ def test_party_json(session):
}

assert party.json == party_json
party.middle_initial = None
del party_json['personName']['middle']
assert party.json == party_json


def test_create_from_json(session):
Expand Down Expand Up @@ -172,7 +175,7 @@ def test_create_from_json(session):
assert party_bus.address.postal_code
assert not party_bus.last_name

party_ind = Party.create_from_json(party_ind_json, 'DB', 1234)
party_ind = Party.create_from_json(party_ind_json, 'DI', 1234)
assert party_ind.registration_id
assert party_ind.party_type == 'DI'
assert party_ind.last_name
Expand All @@ -186,6 +189,9 @@ def test_create_from_json(session):
assert party_ind.address.country
assert party_ind.address.postal_code
assert not party_ind.business_name
del party_ind_json['personName']['middle']
party_ind2 = Party.create_from_json(party_ind_json, 'DI', 1234)
assert party_ind2.middle_initial is None


def test_create_from_financing_json(session):
Expand Down

0 comments on commit 5e4c785

Please sign in to comment.