-
Notifications
You must be signed in to change notification settings - Fork 73
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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']: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
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 |
---|---|---|
|
@@ -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 = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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 { | ||
|
There was a problem hiding this comment.
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)