From 8495e5fad775a4c05c9ee0f225ca235ccb39ef83 Mon Sep 17 00:00:00 2001 From: Doug Lovett Date: Fri, 8 Mar 2024 11:33:40 -0800 Subject: [PATCH] Update amendment reports debtor birthdate change. Signed-off-by: Doug Lovett --- .../template-parts/registration/debtors.html | 12 +++-- .../template-parts/search-result/debtors.html | 5 ++- ppr-api/src/ppr_api/reports/v2/report.py | 35 ++------------- .../src/ppr_api/reports/v2/report_utils.py | 44 +++++++++++++++++++ ppr-api/src/ppr_api/version.py | 2 +- 5 files changed, 62 insertions(+), 36 deletions(-) diff --git a/ppr-api/report-templates/template-parts/registration/debtors.html b/ppr-api/report-templates/template-parts/registration/debtors.html index 49b531e05..74a836c55 100644 --- a/ppr-api/report-templates/template-parts/registration/debtors.html +++ b/ppr-api/report-templates/template-parts/registration/debtors.html @@ -68,7 +68,7 @@ {% if party.address_change is defined %}
ADDRESS CHANGED
{% endif %} - {% else %} + {% elif party.birthdate_change is not defined %}
ADDED
{% endif %} @@ -83,7 +83,10 @@ {% if party.personName is defined %}
Birthdate
{% if party.birthDate is defined %}{{ party.birthDate }}{% endif %}
- {% endif %} + {% if party.birthdate_change is defined %} +
CHANGED
+ {% endif %} + {% endif %} {% if not loop.last %} @@ -153,7 +156,7 @@ {% if party.address_change is defined %}
ADDRESS CHANGED
{% endif %} - {% else %} + {% elif party.birthdate_change is not defined %}
ADDED
{% endif %} @@ -168,6 +171,9 @@ {% if party.personName is defined %}
Birthdate
{% if party.birthDate is defined %}{{ party.birthDate }}{% endif %}
+ {% if party.birthdate_change is defined %} +
CHANGED
+ {% endif %} {% endif %} diff --git a/ppr-api/report-templates/template-parts/search-result/debtors.html b/ppr-api/report-templates/template-parts/search-result/debtors.html index 4fa9da6ac..4f2bbc88c 100644 --- a/ppr-api/report-templates/template-parts/search-result/debtors.html +++ b/ppr-api/report-templates/template-parts/search-result/debtors.html @@ -62,7 +62,7 @@ {% if party.address_change is defined %}
ADDRESS CHANGED
{% endif %} - {% else %} + {% elif party.birthdate_change is not defined %}
ADDED
{% endif %} @@ -77,6 +77,9 @@ {% if party.personName is defined %}
Birthdate
{% if party.birthDate is defined %}{{ party.birthDate }}{% endif %}
+ {% if party.birthdate_change is defined %} +
CHANGED
+ {% endif %} {% endif %} diff --git a/ppr-api/src/ppr_api/reports/v2/report.py b/ppr-api/src/ppr_api/reports/v2/report.py index a333e46a0..e05b1fb9c 100755 --- a/ppr-api/src/ppr_api/reports/v2/report.py +++ b/ppr-api/src/ppr_api/reports/v2/report.py @@ -662,40 +662,13 @@ def _set_amend_party_addresses(self, statement): def _set_modified_party(add_party, delete_parties): """Set the update flags for a single party .""" for delete_party in delete_parties: - if 'reg_id' in add_party and 'reg_id' in delete_party and \ + if add_party.get('reg_id') and delete_party.get('reg_id') and \ add_party['reg_id'] == delete_party['reg_id'] and 'edit' not in delete_party: if add_party.get('amendPartyId', 0) > 0 and add_party['amendPartyId'] == delete_party.get('partyId'): - delete_party['edit'] = True - if 'businessName' in add_party and 'businessName' in delete_party and \ - add_party['businessName'] != delete_party['businessName']: - add_party['name_change'] = True - elif 'personName' in add_party and 'personName' in delete_party and \ - add_party['personName'] != delete_party['personName']: - add_party['name_change'] = True - else: - add_party['address_change'] = True - break + report_utils.set_party_change_type(add_party, delete_party, True) if 'amendPartyId' not in add_party: - if add_party['address'] == delete_party['address']: - if 'businessName' in add_party and 'businessName' in delete_party and \ - add_party['businessName'] != delete_party['businessName']: - add_party['name_change'] = True - delete_party['edit'] = True - break - if 'personName' in add_party and 'personName' in delete_party and \ - add_party['personName'] != delete_party['personName']: - add_party['name_change'] = True - delete_party['edit'] = True - break - elif 'businessName' in add_party and 'businessName' in delete_party and \ - add_party['businessName'] == delete_party['businessName']: - add_party['address_change'] = True - delete_party['edit'] = True - break - elif 'personName' in add_party and 'personName' in delete_party and \ - add_party['personName'] == delete_party['personName']: - add_party['address_change'] = True - delete_party['edit'] = True + report_utils.set_party_change_type(add_party, delete_party, True) + if delete_party.get('edit'): break def _set_modified_parties(self, statement): diff --git a/ppr-api/src/ppr_api/reports/v2/report_utils.py b/ppr-api/src/ppr_api/reports/v2/report_utils.py index 86887b682..58483461a 100755 --- a/ppr-api/src/ppr_api/reports/v2/report_utils.py +++ b/ppr-api/src/ppr_api/reports/v2/report_utils.py @@ -592,3 +592,47 @@ def format_description(description: str) -> str: doc_desc = doc_desc.replace(' Under ', ' under ') doc_desc = doc_desc.replace(' In ', ' in ') return doc_desc + + +def is_same_name(add_party: dict, delete_party: dict) -> bool: + """Determine if party names are identical.""" + if add_party.get('businessName') and delete_party.get('businessName') and \ + add_party['businessName'] == delete_party['businessName']: + return True + if add_party.get('personName') and delete_party.get('personName') and \ + add_party['personName'] == delete_party['personName']: + return True + return False + + +def set_party_change_type(add_party, delete_party, is_same_party_id: bool): + """Conditionally set the name/address/birthdate change type for a single party .""" + name_change: bool = False + address_change: bool = False + birthdate_change: bool = False + if is_same_party_id: + delete_party['edit'] = True + if not is_same_name(add_party, delete_party): + name_change = True + if add_party.get('address') != delete_party.get('address'): + address_change = True + if not (address_change and name_change) \ + and add_party.get('birthDate', '') != delete_party.get('birthDate', ''): + birthdate_change = True + else: + same_name: bool = is_same_name(add_party, delete_party) + same_address: bool = add_party['address'] == delete_party['address'] + if not same_name: + name_change = True + if not same_address: + address_change = True + if (same_address or same_name) and add_party.get('birthDate', '') != delete_party.get('birthDate', ''): + birthdate_change = True + if name_change and not address_change: + add_party['name_change'] = True + elif not name_change and address_change: + add_party['address_change'] = True + if birthdate_change: + add_party['birthdate_change'] = True + if add_party.get('name_change') or add_party.get('address_change') or add_party.get('birthdate_change'): + delete_party['edit'] = True diff --git a/ppr-api/src/ppr_api/version.py b/ppr-api/src/ppr_api/version.py index b9f713d1f..46bef6112 100644 --- a/ppr-api/src/ppr_api/version.py +++ b/ppr-api/src/ppr_api/version.py @@ -22,4 +22,4 @@ Development release segment: .devN """ -__version__ = '1.2.1' # pylint: disable=invalid-name +__version__ = '1.2.2' # pylint: disable=invalid-name