From 71abcb923addc0ec1dc246153774d62dfc83e0ed Mon Sep 17 00:00:00 2001 From: EasonPan Date: Tue, 24 Dec 2024 13:10:12 -0800 Subject: [PATCH] 23350 - notice of withdrawal outputs - focus on NoW for existing businesses (#3148) * create template for NoW and format it * update business details for NoW * update receipt data for NoW --- .../report-templates/noticeOfWithdrawal.html | 33 +++++++ .../common/businessDetails.html | 26 ++++- .../template-parts/common/style.html | 9 ++ .../recordToBeWithdrawn.html | 17 ++++ legal-api/src/legal_api/reports/report.py | 21 +++- .../business_filings/business_documents.py | 3 +- legal-api/tests/unit/reports/test_report.py | 97 ++++++++++++++++++- 7 files changed, 201 insertions(+), 5 deletions(-) create mode 100644 legal-api/report-templates/noticeOfWithdrawal.html create mode 100644 legal-api/report-templates/template-parts/notice-of-withdrawal/recordToBeWithdrawn.html diff --git a/legal-api/report-templates/noticeOfWithdrawal.html b/legal-api/report-templates/noticeOfWithdrawal.html new file mode 100644 index 0000000000..59aaa17815 --- /dev/null +++ b/legal-api/report-templates/noticeOfWithdrawal.html @@ -0,0 +1,33 @@ +[[macros.html]] + + + + Notice of Withdrawal + + + [[common/style.html]] + + +
+ + + + + + +
+ +
+
+ [[common/businessDetails.html]] +
NOTICE OF WITHDRAWAL
+
+ [[notice-of-withdrawal/recordToBeWithdrawn.html]] +
+ + \ No newline at end of file diff --git a/legal-api/report-templates/template-parts/common/businessDetails.html b/legal-api/report-templates/template-parts/common/businessDetails.html index f26c60eaac..03b0561663 100644 --- a/legal-api/report-templates/template-parts/common/businessDetails.html +++ b/legal-api/report-templates/template-parts/common/businessDetails.html @@ -328,6 +328,28 @@ {% endif %}
{{report_date_time}}
+ {% elif header.name == 'noticeOfWithdrawal' %} + + {% if not business or business.identifier.startswith('T') %} +
Filed Date and Time:
+ {% else %} +
Incorporation Number:
+
Filed Date and Time:
+ {% endif %} +
Recognition Date and Time:
+
Retrieved Date and Time:
+ + + {% if not business or business.identifier.startswith('T') %} +
{{ filing_date_time }}
+
{{ effective_date_time }}
+ {% else %} +
{{business.identifier}}
+
{{ filing_date_time }}
+
{{ recognition_date_time }}
+ {% endif %} +
{{ report_date_time }}
+ {% endif %} {% if reportType != 'summary' %} @@ -359,8 +381,8 @@ {% if business.legalType in ['SP', 'GP'] %} | Registration #{{business.identifier}} {% else %} - {% if header.name != 'incorporationApplication' %} - + {% if header.name not in ['incorporationApplication', 'noticeOfWithdrawal'] %} + | Incorporation # {% if not business or business.identifier.startswith('T') %} Pending diff --git a/legal-api/report-templates/template-parts/common/style.html b/legal-api/report-templates/template-parts/common/style.html index 08c373d572..26820ee0c6 100644 --- a/legal-api/report-templates/template-parts/common/style.html +++ b/legal-api/report-templates/template-parts/common/style.html @@ -329,6 +329,15 @@ text-align: center } + .record-to-be-withdrawn-table { + width: 100%; + font-family: 'BCSans-Regular', sans-serif !important; + color: #313132; + font-size: 13px; + line-height: 16px; + text-align: left; + } + .share-structure-table { width: 100%; border-collapse: collapse; diff --git a/legal-api/report-templates/template-parts/notice-of-withdrawal/recordToBeWithdrawn.html b/legal-api/report-templates/template-parts/notice-of-withdrawal/recordToBeWithdrawn.html new file mode 100644 index 0000000000..179f393538 --- /dev/null +++ b/legal-api/report-templates/template-parts/notice-of-withdrawal/recordToBeWithdrawn.html @@ -0,0 +1,17 @@ +
+
Record to be Withdrawn
+ + + + + + +
\ No newline at end of file diff --git a/legal-api/src/legal_api/reports/report.py b/legal-api/src/legal_api/reports/report.py index facc8af50c..690a963c6a 100644 --- a/legal-api/src/legal_api/reports/report.py +++ b/legal-api/src/legal_api/reports/report.py @@ -24,7 +24,7 @@ from dateutil.relativedelta import relativedelta from flask import current_app, jsonify -from legal_api.core.meta.filing import FILINGS +from legal_api.core.meta.filing import FILINGS, FilingMeta from legal_api.models import ( AmalgamatingBusiness, Amalgamation, @@ -174,6 +174,7 @@ def _substitute_template_parts(template_code): 'change-of-registration/addresses', 'change-of-registration/proprietor', 'change-of-registration/partner', + 'notice-of-withdrawal/recordToBeWithdrawn', 'incorporation-application/benefitCompanyStmt', 'incorporation-application/completingParty', 'incorporation-application/effectiveDate', @@ -306,6 +307,8 @@ def _format_filing_json(self, filing): # pylint: disable=too-many-branches, too self._format_continuation_in_data(filing) elif self._report_key == 'certificateOfContinuation': self._format_certificate_of_continuation_in_data(filing) + elif self._report_key == 'noticeOfWithdrawal': + self._format_notice_of_withdrawal_data(filing) else: # set registered office address from either the COA filing or status quo data in AR filing with suppress(KeyError): @@ -748,6 +751,18 @@ def _format_amalgamation_data(self, filing): def _format_certificate_of_amalgamation_data(self, filing): self._set_amalgamating_businesses(filing) + def _format_notice_of_withdrawal_data(self, filing): + withdrawn_filing_id = filing['noticeOfWithdrawal']['filingId'] + withdrawn_filing = Filing.find_by_id(withdrawn_filing_id) + formatted_withdrawn_filing_type = FilingMeta.get_display_name( + withdrawn_filing.filing_json['filing']['business']['legalType'], + withdrawn_filing.filing_type, + withdrawn_filing.filing_sub_type + ) + filing['withdrawnFilingType'] = formatted_withdrawn_filing_type + withdrawn_filing_date = LegislationDatetime.as_legislation_timezone(withdrawn_filing.effective_date) + filing['withdrawnFilingEffectiveDate'] = LegislationDatetime.format_as_report_string(withdrawn_filing_date) + def _set_amalgamating_businesses(self, filing): amalgamating_businesses = [] business_legal_name = None @@ -1460,6 +1475,10 @@ class ReportMeta: # pylint: disable=too-few-public-methods 'certificateOfContinuation': { 'filingDescription': 'Certificate of Continuation', 'fileName': 'certificateOfContinuation' + }, + 'noticeOfWithdrawal': { + 'filingDescription': 'Notice of Withdrawal', + 'fileName': 'noticeOfWithdrawal' } } diff --git a/legal-api/src/legal_api/resources/v2/business/business_filings/business_documents.py b/legal-api/src/legal_api/resources/v2/business/business_filings/business_documents.py index 5b62e18a3e..59ce9c1937 100644 --- a/legal-api/src/legal_api/resources/v2/business/business_filings/business_documents.py +++ b/legal-api/src/legal_api/resources/v2/business/business_filings/business_documents.py @@ -110,7 +110,8 @@ def _get_receipt(business: Business, filing: Filing, token): return {}, HTTPStatus.BAD_REQUEST effective_date = None - if filing.storage.effective_date.date() != filing.storage.filing_date.date(): + if filing.storage.effective_date.date() != filing.storage.filing_date.date() \ + or filing.filing_type == 'noticeOfWithdrawal': effective_date = LegislationDatetime.format_as_report_string(filing.storage.effective_date) headers = {'Authorization': 'Bearer ' + token} diff --git a/legal-api/tests/unit/reports/test_report.py b/legal-api/tests/unit/reports/test_report.py index 5ac9632db2..05652094df 100644 --- a/legal-api/tests/unit/reports/test_report.py +++ b/legal-api/tests/unit/reports/test_report.py @@ -15,12 +15,14 @@ """Test-Suite to ensure that the Report class is working as expected.""" import copy from contextlib import suppress +from datetime import datetime, timedelta from pathlib import Path from unittest.mock import patch import pytest from flask import current_app from registry_schemas.example_data import ( + AGM_LOCATION_CHANGE, ALTERATION_FILING_TEMPLATE, ANNUAL_REPORT, CHANGE_OF_ADDRESS, @@ -31,6 +33,8 @@ CORRECTION_COMBINED_AR, DISSOLUTION, FILING_HEADER, + NOTICE_OF_WITHDRAWAL, + RESTORATION, INCORPORATION_FILING_TEMPLATE, SPECIAL_RESOLUTION, TRANSITION_FILING_TEMPLATE, @@ -40,7 +44,8 @@ from legal_api.models.db import versioning_manager from legal_api.reports.report import Report # noqa:I001 from legal_api.services import VersionedBusinessDetailsService # noqa:I001 -from tests.unit.models import factory_business, factory_completed_filing # noqa:E501,I001 +from legal_api.utils.legislation_datetime import LegislationDatetime +from tests.unit.models import factory_business, factory_completed_filing, factory_pending_filing # noqa:E501,I001 def create_report(identifier, entity_type, report_type, filing_type, template): @@ -293,3 +298,93 @@ def create_alteration_report(filing, business, report_type): set_registrar_info(report) set_meta_info(report) return report + + +@pytest.mark.parametrize( + 'test_name, identifier, entity_type, filing_template, filing_type, formatted_filing_type', + [ + ('BC agmLocationChange', 'BC1234567', 'BC', AGM_LOCATION_CHANGE, 'agmLocationChange', 'AGM Location Change'), + ('BC alteration', 'BC1234567', 'BC', ALTERATION_FILING_TEMPLATE, 'alteration', 'Alteration'), + ('BC changeOfAddress', 'BC1234567', 'BC', CHANGE_OF_ADDRESS, 'changeOfAddress', 'Address Change'), + ('BC changeOfDirectors', 'BC1234567', 'BC', CHANGE_OF_DIRECTORS, 'changeOfDirectors', 'Director Change'), + ('BC dissolution', 'BC1234567', 'BC', DISSOLUTION, 'dissolution', 'Voluntary Dissolution'), + ('BC restoration', 'BC1234567', 'BC', RESTORATION, 'restoration', 'Full Restoration Application'), + ('BEN agmLocationChange', 'BC1234567', 'BEN', AGM_LOCATION_CHANGE, 'agmLocationChange', 'AGM Location Change'), + ('BEN alteration', 'BC1234567', 'BEN', ALTERATION_FILING_TEMPLATE, 'alteration', 'Alteration'), + ('BEN changeOfAddress', 'BC1234567', 'BEN', CHANGE_OF_ADDRESS, 'changeOfAddress', 'Address Change'), + ('BEN changeOfDirectors', 'BC1234567', 'BEN', CHANGE_OF_DIRECTORS, 'changeOfDirectors', 'Director Change'), + ('BEN dissolution', 'BC1234567', 'BEN', DISSOLUTION, 'dissolution', 'Voluntary Dissolution'), + ('BEN restoration', 'BC1234567', 'BEN', RESTORATION, 'restoration', 'Full Restoration Application'), + ('ULC agmLocationChange', 'BC1234567', 'ULC', AGM_LOCATION_CHANGE, 'agmLocationChange', 'AGM Location Change'), + ('ULC alteration', 'BC1234567', 'ULC', ALTERATION_FILING_TEMPLATE, 'alteration', 'Alteration'), + ('ULC changeOfAddress', 'BC1234567', 'ULC', CHANGE_OF_ADDRESS, 'changeOfAddress', 'Address Change'), + ('ULC changeOfDirectors', 'BC1234567', 'ULC', CHANGE_OF_DIRECTORS, 'changeOfDirectors', 'Director Change'), + ('ULC dissolution', 'BC1234567', 'ULC', DISSOLUTION, 'dissolution', 'Voluntary Dissolution'), + ('ULC restoration', 'BC1234567', 'ULC', RESTORATION, 'restoration', 'Full Restoration Application'), + ('CC agmLocationChange', 'BC1234567', 'CC', AGM_LOCATION_CHANGE, 'agmLocationChange', 'AGM Location Change'), + ('CC alteration', 'BC1234567', 'CC', ALTERATION_FILING_TEMPLATE, 'alteration', 'Alteration'), + ('CC changeOfAddress', 'BC1234567', 'CC', CHANGE_OF_ADDRESS, 'changeOfAddress', 'Address Change'), + ('CC changeOfDirectors', 'BC1234567', 'CC', CHANGE_OF_DIRECTORS, 'changeOfDirectors', 'Director Change'), + ('CC dissolution', 'BC1234567', 'CC', DISSOLUTION, 'dissolution', 'Voluntary Dissolution'), + ('CC restoration', 'BC1234567', 'CC', RESTORATION, 'restoration', 'Full Restoration Application'), + ('C agmLocationChange', 'C1234567', 'C', AGM_LOCATION_CHANGE, 'agmLocationChange', 'AGM Location Change'), + ('C alteration', 'C1234567', 'C', ALTERATION_FILING_TEMPLATE, 'alteration', 'Alteration'), + ('C changeOfAddress', 'C1234567', 'C', CHANGE_OF_ADDRESS, 'changeOfAddress', 'Address Change'), + ('C changeOfDirectors', 'C1234567', 'C', CHANGE_OF_DIRECTORS, 'changeOfDirectors', 'Director Change'), + ('C dissolution', 'C1234567', 'C', DISSOLUTION, 'dissolution', 'Voluntary Dissolution'), + ('C restoration', 'C1234567', 'C', RESTORATION, 'restoration', 'Full Restoration Application'), + ('CUL agmLocationChange', 'C1234567', 'CUL', AGM_LOCATION_CHANGE, 'agmLocationChange', 'AGM Location Change'), + ('CUL alteration', 'C1234567', 'CUL', ALTERATION_FILING_TEMPLATE, 'alteration', 'Alteration'), + ('CUL changeOfAddress', 'C1234567', 'CUL', CHANGE_OF_ADDRESS, 'changeOfAddress', 'Address Change'), + ('CUL changeOfDirectors', 'C1234567', 'CUL', CHANGE_OF_DIRECTORS, 'changeOfDirectors', 'Director Change'), + ('CUL dissolution', 'C1234567', 'CUL', DISSOLUTION, 'dissolution', 'Voluntary Dissolution'), + ('CUL restoration', 'C1234567', 'CUL', RESTORATION, 'restoration', 'Full Restoration Application'), + ('CBEN agmLocationChange', 'C1234567', 'CBEN', AGM_LOCATION_CHANGE, 'agmLocationChange', 'AGM Location Change'), + ('CBEN alteration', 'C1234567', 'CBEN', ALTERATION_FILING_TEMPLATE, 'alteration', 'Alteration'), + ('CBEN changeOfAddress', 'C1234567', 'CBEN', CHANGE_OF_ADDRESS, 'changeOfAddress', 'Address Change'), + ('CBEN changeOfDirectors', 'C1234567', 'CBEN', CHANGE_OF_DIRECTORS, 'changeOfDirectors', 'Director Change'), + ('CBEN dissolution', 'C1234567', 'CBEN', DISSOLUTION, 'dissolution', 'Voluntary Dissolution'), + ('CBEN restoration', 'C1234567', 'CBEN', RESTORATION, 'restoration', 'Full Restoration Application'), + ('CCC agmLocationChange', 'C1234567', 'CCC', AGM_LOCATION_CHANGE, 'agmLocationChange', 'AGM Location Change'), + ('CCC alteration', 'C1234567', 'CCC', ALTERATION_FILING_TEMPLATE, 'alteration', 'Alteration'), + ('CCC changeOfAddress', 'C1234567', 'CCC', CHANGE_OF_ADDRESS, 'changeOfAddress', 'Address Change'), + ('CCC changeOfDirectors', 'C1234567', 'CCC', CHANGE_OF_DIRECTORS, 'changeOfDirectors', 'Director Change'), + ('CCC dissolution', 'C1234567', 'CCC', DISSOLUTION, 'dissolution', 'Voluntary Dissolution'), + ('CCC restoration', 'C1234567', 'CCC', RESTORATION, 'restoration', 'Full Restoration Application') + ] +) +def test_notice_of_withdraw_format_data(session, test_name, identifier, entity_type, filing_template, filing_type, formatted_filing_type): + """Test the data passed to NoW report template - existing business""" + # create a business + test_business = factory_business(identifier=identifier, entity_type=entity_type) + + # file a FE filing + today = datetime.utcnow().date() + future_effective_date = today + timedelta(days=5) + future_effective_date = future_effective_date.isoformat() + withdrawn_json = copy.deepcopy(FILING_HEADER) + withdrawn_json['filing']['header']['name'] = filing_type + withdrawn_json['filing']['business']['legalType'] = entity_type + withdrawn_json['filing'][filing_type] = copy.deepcopy(filing_template) + withdrawn_filing = factory_pending_filing(test_business, withdrawn_json) + withdrawn_filing.effective_date = future_effective_date + withdrawn_filing.payment_completion_date = today.isoformat() + withdrawn_filing.save() + withdrawn_filing_id = withdrawn_filing.id + + # file a NoW filing + now_json = copy.deepcopy(FILING_HEADER) + now_json['filing']['header']['name'] = 'noticeOfWithdrawal' + now_json['filing']['business']['legalType'] = 'BC' + now_json['filing']['noticeOfWithdrawal'] = copy.deepcopy(NOTICE_OF_WITHDRAWAL) + now_json['filing']['noticeOfWithdrawal']['filingId'] = withdrawn_filing_id + + # verify formatted NoW data for report template + formatted_now_json = copy.deepcopy(now_json['filing']) + report_instance = Report({}) + expected_withdrawn_filing_effective_date = LegislationDatetime.as_legislation_timezone(withdrawn_filing.effective_date) + expected_withdrawn_filing_effective_date = LegislationDatetime.format_as_report_string(expected_withdrawn_filing_effective_date) + report_instance._format_notice_of_withdrawal_data(formatted_now_json) + assert formatted_now_json['withdrawnFilingType'] == formatted_filing_type + assert formatted_now_json['withdrawnFilingEffectiveDate'] == expected_withdrawn_filing_effective_date + assert formatted_now_json['noticeOfWithdrawal']['filingId'] == withdrawn_filing_id