Skip to content

Commit

Permalink
22363 Continuation in email templates (#2946)
Browse files Browse the repository at this point in the history
* - added attachment for RESUBMITTED continuation in
- added subjects for other statuses/options
- created APPROVED email template
- created CHANGE_REQUESTED email template
- created REJECTED email template
- created RESUBMITTED email template

* - added latest_review_comment template variable
- updated Rejected template

* - removed debugging code

* - sorted subject if-else conditions
- expanded continuation in tests

* - updated unit test

* - used "in" to reduce duplication

---------

Co-authored-by: Severin Beauvais <[email protected]>
  • Loading branch information
severinbeauvais and Severin Beauvais authored Aug 28, 2024
1 parent d45d405 commit 5a14c84
Show file tree
Hide file tree
Showing 6 changed files with 336 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from entity_queue_common.service_utils import logger
from flask import current_app
from jinja2 import Template
from legal_api.models import Business, Filing
from legal_api.models import Business, Filing, ReviewResult

from entity_emailer.email_processors import (
get_entity_dashboard_url,
Expand Down Expand Up @@ -66,6 +66,7 @@ def _get_pdfs(
)
attach_order += 1

# add receipt
corp_name = business.get('legalName')
receipt = requests.post(
f'{current_app.config.get("PAY_API_URL")}/{filing.payment_token}/receipts',
Expand All @@ -91,6 +92,22 @@ def _get_pdfs(
}
)
attach_order += 1

elif status == 'RESUBMITTED':
# add filing pdf
filing_pdf_type = 'continuationIn'
filing_pdf_encoded = get_filing_document(business['identifier'], filing.id, filing_pdf_type, token)
if filing_pdf_encoded:
pdfs.append(
{
'fileName': 'Continuation Application - Resubmitted.pdf',
'fileBytes': filing_pdf_encoded.decode('utf-8'),
'fileUrl': '',
'attachOrder': str(attach_order)
}
)
attach_order += 1

elif status == Filing.Status.COMPLETED.value:
# add certificate of continuation
certificate_pdf_type = 'certificateOfContinuation'
Expand All @@ -105,6 +122,7 @@ def _get_pdfs(
}
)
attach_order += 1

# add notice of articles
noa_pdf_type = 'noticeOfArticles'
noa_encoded = get_filing_document(business['identifier'], filing.id, noa_pdf_type, token)
Expand All @@ -118,28 +136,29 @@ def _get_pdfs(
}
)
attach_order += 1

return pdfs


def process(email_info: dict, token: str) -> dict: # pylint: disable=too-many-locals, , too-many-branches
"""Build the email for Continuation notification."""
logger.debug('filing_notification: %s', email_info)
# get template and fill in parts

# get template vars from email info
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

template = Path(f'{current_app.config.get("TEMPLATE_PATH")}/CONT-IN-{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)
review_result = ReviewResult.get_last_review_result(filing.id)
# encode newlines in review comment only
latest_review_comment = review_result.comments.replace('\n', '\\n') if review_result else None

# compute Foreign Jurisdiction string as in report.py and business_document.py
country_code = filing_data['foreignJurisdiction']['country']
Expand All @@ -150,6 +169,12 @@ def process(email_info: dict, token: str) -> dict: # pylint: disable=too-many-l
region = pycountry.subdivisions.get(code=f'{country_code}-{region_code}')
foreign_jurisdiction = f'{region.name}, {country.name}' if region else country.name

# get template and fill in parts
template = Path(f'{current_app.config.get("TEMPLATE_PATH")}/CONT-IN-{status}.html').read_text()
filled_template = substitute_template_parts(template)
jnja_template = Template(filled_template, autoescape=True)

# render template with vars
html_out = jnja_template.render(
business=business,
filing=filing_data,
Expand All @@ -161,9 +186,13 @@ def process(email_info: dict, token: str) -> dict: # pylint: disable=too-many-l
email_header=filing_name.upper(),
filing_type=filing_type,
numbered_description=numbered_description,
foreign_jurisdiction=foreign_jurisdiction
foreign_jurisdiction=foreign_jurisdiction,
latest_review_comment=latest_review_comment
)

# decode newlines to <br> for html output
html_out = html_out.replace('\\n', '<br>')

# get attachments
pdfs = _get_pdfs(status,
token,
Expand All @@ -179,10 +208,14 @@ def process(email_info: dict, token: str) -> dict: # pylint: disable=too-many-l

# assign subject
legal_name = business.get('legalName', None)
if status == Filing.Status.PAID.value:
subject = 'Confirmation of Filing from the Business Registry'
if status in [Filing.Status.APPROVED.value, Filing.Status.REJECTED.value]:
subject = 'Results of your Filing from the Business Registry'
elif status == Filing.Status.CHANGE_REQUESTED.value:
subject = 'Change Requested from the Business Registry'
elif status == Filing.Status.COMPLETED.value:
subject = 'Continuation Documents from the Business Registry'
elif status in [Filing.Status.PAID.value, 'RESUBMITTED']:
subject = 'Confirmation of Filing from the Business Registry'

subject = f'{legal_name} - {subject}' if legal_name else subject

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="referrer" content="origin-when-cross-origin"/>
<meta name="author" content="BC Registries and Online Services">
<title>Results of your Continuation Application</title>
[[style.html]]
</head>

<body>
<table class="body-table" role="presentation">
<tr>
<td>
[[header.html]]

<div class="container">
<!-- first section -->
<p class="title-message bold">Results of your Continuation Application</p>

<p>Your Continuation Authorization is <span class="bold">approved</span>.</p>

[[20px.html]]
[[divider.html]]
[[20px.html]]

<!-- second section -->
<p class="title-message bold">Your Next Steps</p>

<ol class="outputs">
<li>Receive confirmation that your business has been continued in.</li>
<li>Visit <a href="{{ entity_dashboard_url }}">BC Business Registry account</a> to access
your business.</li>
</ol>

[[20px.html]]
[[divider.html]]
[[20px.html]]

<!-- third section -->
[[continuation-application-details.html]]

[[20px.html]]
[[divider.html]]
[[20px.html]]

<!-- fourth section -->
<p class="title-message bold">Attached to this Email</p>

<p>The following document is attached to this email:</p>
<ul class="outputs">
<li>Continuation Application</li>
</ul>

[[business-dashboard-link.html]]

<!-- fifth section -->
[[24px.html]]
[[footer.html]]
</div>
</td>
</tr>
</table>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="referrer" content="origin-when-cross-origin"/>
<meta name="author" content="BC Registries and Online Services">
<title>Results of your Continuation Application</title>
[[style.html]]
</head>

<body>
<table class="body-table" role="presentation">
<tr>
<td>
[[header.html]]

<div class="container">
<!-- first section -->
<p class="title-message bold">Results of your Continuation Application</p>

<p>Your Continuation Authorization is <span class="bold">not yet approved</span>. Follow
the steps below to modify and resubmit your application.</p>

[[20px.html]]
[[divider.html]]
[[20px.html]]

<!-- second section -->
<p class="title-message bold">Your Next Steps</p>

<p>Follow these steps to complete your application:</p>
<ol class="outputs">
<li>Visit <a href="{{ entity_dashboard_url }}">BC Business Registry account</a>.</li>
<li>Modify the application to satisfy the request from staff as described below:</li>
</ol>

<pre class="bold">{{ latest_review_comment }}</pre>

[[20px.html]]
[[divider.html]]
[[20px.html]]

<!-- third section -->
[[continuation-application-details.html]]

<!-- fourth section -->
[[24px.html]]
[[footer.html]]
</div>
</td>
</tr>
</table>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="referrer" content="origin-when-cross-origin"/>
<meta name="author" content="BC Registries and Online Services">
<title>Results of your Continuation Application</title>
[[style.html]]
</head>

<body>
<table class="body-table" role="presentation">
<tr>
<td>
[[header.html]]

<div class="container">
<!-- first section -->
<p class="title-message bold">Results of your Continuation Application</p>

<p>Your Continuation Authorization is <span class="bold">rejected</span> and a refund request
has been submitted. The refund will be applied to your original payment method. Refunds
are usually processed within 10-14 business days.</p>

[[20px.html]]
[[divider.html]]
[[20px.html]]

<!-- second section -->
<p class="title-message bold">Your Next Steps</p>

<ol class="outputs">
<li>Review the reasons for rejected as outlined below:</li>
<pre class="bold">{{ latest_review_comment }}</pre>
<li>Visit <a href="{{ entity_dashboard_url }}">BC Business Registry account</a> to submit
a new Continuation Application.</li>
</ol>


[[20px.html]]
[[divider.html]]
[[20px.html]]

<!-- third section -->
[[continuation-application-details.html]]

[[20px.html]]
[[divider.html]]
[[20px.html]]

<!-- fourth section -->
<p class="title-message bold">Attached to this Email</p>

<p>The following document is attached to this email:</p>
<ul class="outputs">
<li>Continuation Application - Rejected</li>
</ul>

[[business-dashboard-link.html]]

<!-- fifth section -->
[[24px.html]]
[[footer.html]]
</div>
</td>
</tr>
</table>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="referrer" content="origin-when-cross-origin"/>
<meta name="author" content="BC Registries and Online Services">
<title>Confirmation of Filing from the Business Registry</title>
[[style.html]]
</head>

<body>
<table class="body-table" role="presentation">
<tr>
<td>
[[header.html]]

<div class="container">
<!-- first section -->
<p class="title-message bold">We have received your updated Continuation Application</p>

<p>BC Registries will review your Continuation Authorization documents and contact you
with the results within 2 business days.</p>

[[20px.html]]
[[divider.html]]
[[20px.html]]

<!-- second section -->
[[continuation-application-details.html]]

[[20px.html]]
[[divider.html]]
[[20px.html]]

<!-- third section -->
<p class="title-message bold">Attached to this Email</p>

<p>The following document id attached to this email:</p>
<ul class="outputs">
<li>Continuation Application - Pending</li>
</ul>

[[business-dashboard-link.html]]
[[8px.html]]

<p>
Once your authorization has been approved, your business will be registered and you will
receive the following outputs:
</p>
<ul class="outputs">
<li>Notice of Articles</li>
<li>Certificate of Continuation</li>
</ul>

<!-- fourth section -->
[[24px.html]]
[[footer.html]]
</div>
</td>
</tr>
</table>
</body>
</html>
Loading

0 comments on commit 5a14c84

Please sign in to comment.