diff --git a/queue_services/business-emailer/pyproject.toml b/queue_services/business-emailer/pyproject.toml index 3f737a4e5e..5becd615ef 100644 --- a/queue_services/business-emailer/pyproject.toml +++ b/queue_services/business-emailer/pyproject.toml @@ -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 "] license = "BSD-3-Clause" diff --git a/queue_services/business-emailer/src/business_emailer/email_processors/bn_notification.py b/queue_services/business-emailer/src/business_emailer/email_processors/bn_notification.py index 22ab5623c1..1e7a16cffd 100644 --- a/queue_services/business-emailer/src/business_emailer/email_processors/bn_notification.py +++ b/queue_services/business-emailer/src/business_emailer/email_processors/bn_notification.py @@ -20,7 +20,20 @@ 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: @@ -28,8 +41,8 @@ def process(email_msg: dict) -> dict: 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"]) @@ -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 @@ -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": [] } } @@ -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: @@ -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": [] } } diff --git a/queue_services/business-emailer/src/business_emailer/email_templates/BC-BN.html b/queue_services/business-emailer/src/business_emailer/email_templates/BC-BN.html deleted file mode 100644 index ddf2ac2f20..0000000000 --- a/queue_services/business-emailer/src/business_emailer/email_templates/BC-BN.html +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - {{business.legalName}} - Business Number Information - [[style.html]] - - - - - - - - - - diff --git a/queue_services/business-emailer/src/business_emailer/email_templates/BN-MOVE.html b/queue_services/business-emailer/src/business_emailer/email_templates/BN-MOVE.html deleted file mode 100644 index f514186f54..0000000000 --- a/queue_services/business-emailer/src/business_emailer/email_templates/BN-MOVE.html +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - {{business.legalName}} - Business Number Changed - [[style.html]] - - - - - - - - - - diff --git a/queue_services/business-emailer/src/business_emailer/email_templates/bnGenerated.md b/queue_services/business-emailer/src/business_emailer/email_templates/bnGenerated.md new file mode 100644 index 0000000000..3056780897 --- /dev/null +++ b/queue_services/business-emailer/src/business_emailer/email_templates/bnGenerated.md @@ -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]] diff --git a/queue_services/business-emailer/src/business_emailer/email_templates/bnMove.md b/queue_services/business-emailer/src/business_emailer/email_templates/bnMove.md new file mode 100644 index 0000000000..b7334e9abc --- /dev/null +++ b/queue_services/business-emailer/src/business_emailer/email_templates/bnMove.md @@ -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]] diff --git a/queue_services/business-emailer/tests/unit/email_processors/test_bn_notification.py b/queue_services/business-emailer/tests/unit/email_processors/test_bn_notification.py index 748a897fa4..200cba7f4c 100644 --- a/queue_services/business-emailer/tests/unit/email_processors/test_bn_notification.py +++ b/queue_services/business-emailer/tests/unit/email_processors/test_bn_notification.py @@ -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 @@ -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'] == [] @@ -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'] == [] diff --git a/queue_services/business-emailer/tests/unit/test_worker.py b/queue_services/business-emailer/tests/unit/test_worker.py index 6c6ed49ad5..431be54bbe 100644 --- a/queue_services/business-emailer/tests/unit/test_worker.py +++ b/queue_services/business-emailer/tests/unit/test_worker.py @@ -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 @@ -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'] == []