Skip to content
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
2 changes: 1 addition & 1 deletion queue_services/business-emailer/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "business-emailer"
version = "0.1.18"
version = "0.1.19"
description = "This module is the service worker for sending emails about entity related events."
authors = ["Hrvoje Fekete <hrvoje.fekete@mindpoweredtech.com>"]
license = "BSD-3-Clause"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,29 @@
from jinja2 import Template

from business_emailer.email_processors import get_recipient_from_auth, get_recipients, substitute_template_parts
from business_model.models import Business, CorpType, Filing, PartyRole
from business_emailer.email_processors.util import NOT_AVAILABLE, get_legal_type_key
from business_model.models import Business, Filing, PartyRole


def _get_business_tombstone_context(business: Business, business_number: str) -> dict:
"""Return the values required by the shared business tombstone."""
business_data = business.json()
legal_type_key = get_legal_type_key(business.legal_type)
return {
"business_name": business_data.get("businessName") or business_data.get("legalName") or NOT_AVAILABLE,
"business_identifier": business.identifier,
"business_number": business_number,
"number_description": "Registration" if legal_type_key == "FIRM" else "Incorporation",
}


def process(email_msg: dict) -> dict:
"""Build the email for Business Number notification."""
current_app.logger.debug("bn notification: %s", email_msg)

# get template and fill in parts
template = Path(f'{current_app.config.get("TEMPLATE_PATH")}/BC-BN.html').read_text()
filled_template = substitute_template_parts(template)
template = Path(f'{current_app.config.get("TEMPLATE_PATH")}/bnGenerated.md').read_text()
filled_template = substitute_template_parts(template, "md")

# get filing and business json
business = Business.find_by_identifier(email_msg["identifier"])
Expand All @@ -38,13 +51,12 @@ def process(email_msg: dict) -> dict:
filings = Filing.get_filings_by_types(business.id, ["amalgamationApplication", "continuationIn",
"incorporationApplication", "registration"])
filing = filings[0]
corp_type = CorpType.find_by_id(business.legal_type)
business_number = business.tax_id.replace("BC", " BC")

# render template with vars
jnja_template = Template(filled_template, autoescape=True)
html_out = jnja_template.render(
business=business.json(),
entityDescription=corp_type.full_desc if corp_type else ""
jinja_template = Template(filled_template, autoescape=True)
body = jinja_template.render(
**_get_business_tombstone_context(business, business_number),
entity_dashboard_url=current_app.config.get("DASHBOARD_URL") + business.identifier,
)

# get recipients
Expand All @@ -54,7 +66,7 @@ def process(email_msg: dict) -> dict:
"requestBy": "BCRegistries@gov.bc.ca",
"content": {
"subject": f"{business.legal_name} - Business Number Information",
"body": html_out,
"body": body,
"attachments": []
}
}
Expand All @@ -65,24 +77,25 @@ def process_bn_move(email_msg: dict, token: str) -> dict:
current_app.logger.debug("bn move notification: %s", email_msg)

# get template and fill in parts
template = Path(f'{current_app.config.get("TEMPLATE_PATH")}/BN-MOVE.html').read_text()
filled_template = substitute_template_parts(template)
template = Path(f'{current_app.config.get("TEMPLATE_PATH")}/bnMove.md').read_text()
filled_template = substitute_template_parts(template, "md")

# get filing and business json
business = Business.find_by_identifier(email_msg["identifier"])
corp_type = CorpType.find_by_id(business.legal_type)

# render template with vars
jnja_template = Template(filled_template, autoescape=True)
html_out = jnja_template.render(
business=business.json(),
entityDescription=corp_type.full_desc if corp_type else "",
old_bn=email_msg["oldBn"],
new_bn=email_msg["newBn"]

old_bn = email_msg["oldBn"].replace("BC", " BC")
new_bn = email_msg["newBn"].replace("BC", " BC")

jinja_template = Template(filled_template, autoescape=True)
body = jinja_template.render(
**_get_business_tombstone_context(business, new_bn),
entity_dashboard_url=current_app.config.get("DASHBOARD_URL") + business.identifier,
old_bn=old_bn,
new_bn=new_bn,
)

recipients = []
recipients.append(get_recipient_from_auth(business.identifier, token)) # business email
recipients.append(get_recipient_from_auth(business.identifier, token))

role = ""
if business.legal_type == Business.LegalTypes.SOLE_PROP.value:
Expand All @@ -103,7 +116,7 @@ def process_bn_move(email_msg: dict, token: str) -> dict:
"requestBy": "BCRegistries@gov.bc.ca",
"content": {
"subject": f"{business.legal_name} - Business Number Changed",
"body": html_out,
"body": body,
"attachments": []
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Business number information

---

[[business-tombstone-basic.md]]

---

## Business Number

The Canada Revenue Agency has provided a business number for your business.

**Business Number:** {{ business_number }}

This number can also be seen on your [BC Business Registry dashboard]({{ entity_dashboard_url }}).

---

[[business-registry-footer.md]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Business number changed

---

[[business-tombstone-basic.md]]

---

## Business Number

The Canada Revenue Agency has changed the business number for your business. This number has been automatically updated in the BC Business Registry.

**Old Business Number:** {{old_bn}}

**New Business Number:** {{new_bn}}

This number can also be seen on your [BC Business Registry dashboard]({{ entity_dashboard_url }}).

---

[[business-registry-footer.md]]
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_bootstrap_bn_notificaton(app, session, filing_type, expected_emails):
identifier = 'BC1234567'
filing = prep_bootstrap_filing(session, filing_type, identifier, 'BC', 'COMPLETED')
business = Business.find_by_identifier(identifier)
business.tax_id = '123456789BC0001'
# sanity check
assert filing.id
assert business.id
Expand All @@ -46,7 +47,10 @@ def test_bootstrap_bn_notificaton(app, session, filing_type, expected_emails):
# check email values
assert expected_emails == email['recipients']
assert email['content']['subject'] == f'{business.legal_name} - Business Number Information'
assert email['content']['body']
body = email['content']['body']
assert '# Business number information' in body
assert '**Business Number:** 123456789 BC0001' in body
assert f'[BC Business Registry dashboard]({app.config.get("DASHBOARD_URL")}{identifier})' in body
assert email['content']['attachments'] == []


Expand All @@ -69,5 +73,9 @@ def test_bn_move_notificaton(app, session):
# check email values
assert 'user@email.com' in email['recipients']
assert email['content']['subject'] == f'{business.legal_name} - Business Number Changed'
assert email['content']['body']
body = email['content']['body']
assert '# Business number changed' in body
assert '**Old Business Number:** 993775204 BC0001' in body
assert '**New Business Number:** 993777399 BC0001' in body
assert f'[BC Business Registry dashboard]({app.config.get("DASHBOARD_URL")}{identifier})' in body
assert email['content']['attachments'] == []
6 changes: 5 additions & 1 deletion queue_services/business-emailer/tests/unit/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ def test_process_bn_email(app, session):
identifier = 'BC1234567'
filing = prep_incorp_filing(session, identifier, 'bn', 'BC')
business = Business.find_by_identifier(identifier)
business.tax_id = '123456789BC0001'
# sanity check
assert filing.id
assert business.id
Expand All @@ -326,7 +327,10 @@ def test_process_bn_email(app, session):
assert CONTACT_POINT == mock_send_email.call_args[0][0]['recipients']
assert mock_send_email.call_args[0][0]['content']['subject'] == \
f'{business.legal_name} - Business Number Information'
assert mock_send_email.call_args[0][0]['content']['body']
body = mock_send_email.call_args[0][0]['content']['body']
assert '# Business number information' in body
assert '**Business Number:** 123456789 BC0001' in body
assert f'[BC Business Registry dashboard]({app.config.get("DASHBOARD_URL")}{identifier})' in body
assert mock_send_email.call_args[0][0]['content']['attachments'] == []


Expand Down