diff --git a/legal-api/src/legal_api/models/business.py b/legal-api/src/legal_api/models/business.py index e0da0912e0..7cf1515bea 100644 --- a/legal-api/src/legal_api/models/business.py +++ b/legal-api/src/legal_api/models/business.py @@ -298,8 +298,7 @@ def get_ar_dates(self, next_ar_year): ar_min_date = datetime(next_ar_year, self.founding_date.month, self.founding_date.day).date() ar_max_date = ar_min_date + datedelta.datedelta(days=60) - if ar_max_date > datetime.utcnow().date(): - ar_max_date = datetime.utcnow().date() + ar_max_date = min(ar_max_date, datetime.utcnow().date()) # ar_max_date cannot be in future return ar_min_date, ar_max_date diff --git a/legal-api/src/legal_api/resources/v1/business/business_filings.py b/legal-api/src/legal_api/resources/v1/business/business_filings.py index 9396eb1eed..a497ea8537 100644 --- a/legal-api/src/legal_api/resources/v1/business/business_filings.py +++ b/legal-api/src/legal_api/resources/v1/business/business_filings.py @@ -81,7 +81,7 @@ def get(identifier, filing_id=None): # pylint: disable=too-many-return-statemen if not rv.storage: return jsonify({'message': f'{identifier} no filings found'}), HTTPStatus.NOT_FOUND if str(request.accept_mimetypes) == 'application/pdf' and filing_id: - if rv.filing_type == 'incorporationApplication': + if rv.filing_type in ['amalgamationApplication', 'incorporationApplication']: return legal_api.reports.get_pdf(rv.storage, None) if original_filing: diff --git a/queue_services/entity-emailer/requirements.txt b/queue_services/entity-emailer/requirements.txt index 54e2badab8..cf5b26ae3c 100644 --- a/queue_services/entity-emailer/requirements.txt +++ b/queue_services/entity-emailer/requirements.txt @@ -78,6 +78,6 @@ webcolors==1.13 Werkzeug==1.0.1 yarl==1.8.2 zipp==3.15.0 -git+https://github.com/bcgov/business-schemas.git@2.18.18#egg=registry_schemas +git+https://github.com/bcgov/business-schemas.git@2.18.19#egg=registry_schemas git+https://github.com/bcgov/lear.git#egg=legal_api&subdirectory=legal-api git+https://github.com/bcgov/lear.git#egg=entity_queue_common&subdirectory=queue_services/common diff --git a/queue_services/entity-emailer/requirements/bcregistry-libraries.txt b/queue_services/entity-emailer/requirements/bcregistry-libraries.txt index aeecf53d9e..b4ad4be4ed 100644 --- a/queue_services/entity-emailer/requirements/bcregistry-libraries.txt +++ b/queue_services/entity-emailer/requirements/bcregistry-libraries.txt @@ -1,3 +1,3 @@ -git+https://github.com/bcgov/business-schemas.git@2.18.14#egg=registry_schemas +git+https://github.com/bcgov/business-schemas.git@2.18.19#egg=registry_schemas git+https://github.com/bcgov/lear.git#egg=entity_queue_common&subdirectory=queue_services/common git+https://github.com/bcgov/lear.git#egg=legal_api&subdirectory=legal-api diff --git a/queue_services/entity-emailer/src/entity_emailer/email_processors/amalgamation_notification.py b/queue_services/entity-emailer/src/entity_emailer/email_processors/amalgamation_notification.py index 014893931d..432329172e 100644 --- a/queue_services/entity-emailer/src/entity_emailer/email_processors/amalgamation_notification.py +++ b/queue_services/entity-emailer/src/entity_emailer/email_processors/amalgamation_notification.py @@ -23,7 +23,7 @@ from entity_queue_common.service_utils import logger from flask import current_app from jinja2 import Template -from legal_api.models import Filing +from legal_api.models import AmalgamatingBusiness, Amalgamation, Business, Filing from entity_emailer.email_processors import get_filing_info, get_recipients, substitute_template_parts @@ -34,7 +34,8 @@ def _get_pdfs( business: dict, filing: Filing, filing_date_time: str, - effective_date: str) -> list: + effective_date: str, + amalgamation_application_name: str) -> list: # pylint: disable=too-many-locals, too-many-branches, too-many-statements, too-many-arguments """Get the outputs for the amalgamation notification.""" pdfs = [] @@ -56,7 +57,7 @@ def _get_pdfs( filing_pdf_encoded = base64.b64encode(filing_pdf.content) pdfs.append( { - 'fileName': 'Amalgamation Application.pdf', + 'fileName': f'{amalgamation_application_name}.pdf', 'fileBytes': filing_pdf_encoded.decode('utf-8'), 'fileUrl': '', 'attachOrder': attach_order @@ -134,30 +135,60 @@ def _get_pdfs( def process(email_info: dict, token: str) -> dict: # pylint: disable=too-many-locals, , too-many-branches """Build the email for Amalgamation notification.""" logger.debug('filing_notification: %s', email_info) + amalgamation_application_names = { + Amalgamation.AmalgamationTypes.regular.name: 'Amalgamation Application (Regular)', + Amalgamation.AmalgamationTypes.vertical.name: 'Amalgamation Application Short-form (Vertical)', + Amalgamation.AmalgamationTypes.horizontal.name: 'Amalgamation Application Short-form (Horizontal)' + } # get template and fill in parts filing_type, status = email_info['type'], email_info['option'] # get template vars from filing filing, business, leg_tmz_filing_date, leg_tmz_effective_date = get_filing_info(email_info['filingId']) filing_name = filing.filing_type[0].upper() + ' '.join(re.findall('[a-zA-Z][^A-Z]*', filing.filing_type[1:])) + filing_data = (filing.json)['filing'][f'{filing_type}'] + if status == Filing.Status.PAID.value: + business = filing_data['nameRequest'] + business['identifier'] = filing.temp_reg + + if filing.filing_sub_type in [Amalgamation.AmalgamationTypes.vertical.name, + Amalgamation.AmalgamationTypes.horizontal.name]: + amalgamating_business = next(x for x in filing_data.get('amalgamatingBusinesses') + if x['role'] in [AmalgamatingBusiness.Role.holding.name, + AmalgamatingBusiness.Role.primary.name]) + primary_or_holding_business = Business.find_by_identifier(amalgamating_business['identifier']) + business['legalName'] = primary_or_holding_business.legal_name + + amalgamation_application_name = amalgamation_application_names[filing.filing_sub_type] template = Path(f'{current_app.config.get("TEMPLATE_PATH")}/AMALGA-{status}.html').read_text() filled_template = substitute_template_parts(template) # render template with vars + legal_type = business.get('legalType') + numbered_description = Business.BUSINESSES.get(legal_type, {}).get('numberedDescription') jnja_template = Template(filled_template, autoescape=True) - filing_data = (filing.json)['filing'][f'{filing_type}'] + html_out = jnja_template.render( business=business, filing=filing_data, + filing_status=status, header=(filing.json)['filing']['header'], filing_date_time=leg_tmz_filing_date, effective_date_time=leg_tmz_effective_date, entity_dashboard_url=current_app.config.get('DASHBOARD_URL') + business.get('identifier', ''), email_header=filing_name.upper(), - filing_type=filing_type + filing_type=filing_type, + numbered_description=numbered_description, + amalgamation_application_name=amalgamation_application_name ) # get attachments - pdfs = _get_pdfs(status, token, business, filing, leg_tmz_filing_date, leg_tmz_effective_date) + pdfs = _get_pdfs(status, + token, + business, + filing, + leg_tmz_filing_date, + leg_tmz_effective_date, + amalgamation_application_name) # get recipients recipients = get_recipients(status, filing.filing_json, token, filing_type) @@ -166,8 +197,10 @@ def process(email_info: dict, token: str) -> dict: # pylint: disable=too-many-l # assign subject legal_name = business.get('legalName', None) - subject = f'{legal_name} - Amalgamation' - if status == Filing.Status.COMPLETED.value: + if status == Filing.Status.PAID.value: + subject_prefix = f'{legal_name} - ' if legal_name else '' + subject = f'{subject_prefix}Amalgamation' + elif status == Filing.Status.COMPLETED.value: subject = f'{legal_name} - Confirmation of Amalgamation' return { diff --git a/queue_services/entity-emailer/src/entity_emailer/email_templates/AMALGA-PAID.html b/queue_services/entity-emailer/src/entity_emailer/email_templates/AMALGA-PAID.html index a0a7cdee69..ae3b467adc 100644 --- a/queue_services/entity-emailer/src/entity_emailer/email_templates/AMALGA-PAID.html +++ b/queue_services/entity-emailer/src/entity_emailer/email_templates/AMALGA-PAID.html @@ -18,14 +18,14 @@
The following documents are attached to this email: