Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

19904 email updates for amalgamation application #2478

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions legal-api/src/legal_api/models/business.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new pylint error says Consider using 'ar_max_date = min(ar_max_date, datetime.utcnow().date())' instead of unnecessary if block (consider-using-min-builtin)


return ar_min_date, ar_max_date

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately we are still using v1 resources to get documents in entity-emailer

return legal_api.reports.get_pdf(rv.storage, None)

if original_filing:
Expand Down
2 changes: 1 addition & 1 deletion queue_services/entity-emailer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 = []
Expand All @@ -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
Expand Down Expand Up @@ -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 = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use legal_api/core/meta/filing.py to get displayName but it will cause issues when we merge legal name branch (as we won't keep legal-api dependency anymore)

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)
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

<div class="container">
<p class="title-message bold">
<span>We have received your incorporation application<span>
<span>We have received your amalgamation application<span>
</p>

[[business-information.html]]

<p>The following documents are attached to this email:</p>
<ul class="outputs">
<li>Amalgamation Application</li>
<li>{{ amalgamation_application_name }}</li>
<li>Receipt</li>
</ul>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="name bold">Company Name:</div>
{% endif %}

{% if filing_status == 'PAID' and filing_type == 'incorporationApplication' %}
{% if filing_status == 'PAID' and filing_type in ['amalgamationApplication', 'incorporationApplication'] %}
{% if filing.nameRequest.legalName %}
<!-- try to get legal name from Name Request object -->
<div class="value">{{ filing.nameRequest.legalName }}</div>
Expand All @@ -35,7 +35,7 @@
{% else %}
<div class="name bold">Incorporation Number:</div>
{% endif %}
{% if filing_status == 'PAID' and filing_type == 'incorporationApplication' %}
{% if filing_status == 'PAID' and filing_type in ['amalgamationApplication', 'incorporationApplication'] %}
<div class="value">Pending</div>
{% else %}
<!-- Eg, BC0878529 -->
Expand Down
2 changes: 1 addition & 1 deletion queue_services/entity-emailer/tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ def prep_amalgamation_filing(session, identifier, payment_id, option, legal_name
filing_template['filing']['header']['name'] = 'amalgamationApplication'

filing_template['filing']['amalgamationApplication'] = copy.deepcopy(AMALGAMATION_APPLICATION)
filing_template['filing']['business'] = {
filing_template['filing']['amalgamationApplication']['nameRequest'] = {
'identifier': business.identifier,
'legalType': Business.LegalTypes.BCOMP.value,
'legalName': legal_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def test_amalgamation_notification(app, session, status):
assert email['content']['subject'] == legal_name + ' - Amalgamation'
assert 'comp_party@email.com' in email['recipients']
else:
assert mock_get_pdfs.call_args[0][2]['identifier'] == 'BC1234567'
assert email['content']['subject'] == legal_name + ' - Confirmation of Amalgamation'

assert email['content']['body']
assert email['content']['attachments'] == []
assert mock_get_pdfs.call_args[0][0] == status
assert mock_get_pdfs.call_args[0][1] == token
assert mock_get_pdfs.call_args[0][2]['identifier'] == 'BC1234567'
assert mock_get_pdfs.call_args[0][3] == filing
Loading