Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
corporate: Send fixed-price stale audit log internal billing email.
Lauryn Menard1caff10df7a1
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex 0bc8affcca4..ab0945e9244 100644--- a/corporate/lib/stripe.py+++ b/corporate/lib/stripe.py@@ -5484,6 +5484,7 @@ def maybe_send_stale_audit_log_data_email("billing_entity": billing_session.billing_entity_display_name,"support_url": billing_session.support_url(),"last_audit_log_update": "Never uploaded",+ "fixed_price_plan": plan.fixed_price is not None,"notice_reason": "stale_audit_log_data",}send_email(@@ -5506,6 +5507,7 @@ def maybe_send_stale_audit_log_data_email("billing_entity": billing_session.billing_entity_display_name,"support_url": billing_session.support_url(),"last_audit_log_update": last_audit_log_update.strftime("%Y-%m-%d"),+ "fixed_price_plan": plan.fixed_price is not None,"notice_reason": "stale_audit_log_data",}send_email(@@ -5535,9 +5537,26 @@ def check_remote_server_audit_log_data(# won't change the amount due or the fact that we should downgrade the# plan when it is scheduled to end.if plan.fixed_price is not None:- # TODO: Possibly send an internal billing notice so that billing admin- # have a record that the customer's license ledger entries do not- # reflect actual audit log data from the remote server.+ # Send an internal billing notice so that admin can follow up in the+ # case that the remote server is not regularly updating audit log data,+ # but since the fixed-price plan will be invoiced, we don't set the+ # stale_audit_log_data_email_sent field on the CustomerPlan.+ context = {+ "billing_entity": billing_session.billing_entity_display_name,+ "support_url": billing_session.support_url(),+ "fixed_price_plan": plan.fixed_price is not None,+ "notice_reason": "stale_audit_log_data",+ }+ if last_audit_log_update is None: # nocoverage+ context["last_audit_log_update"] = "Never uploaded"+ else:+ context["last_audit_log_update"] = last_audit_log_update.strftime("%Y-%m-%d")+ send_email(+ "zerver/emails/internal_billing_notice",+ to_emails=[BILLING_SUPPORT_EMAIL],+ from_address=FromAddress.tokenized_no_reply_address(),+ context=context,+ )return Trueif not plan.stale_audit_log_data_email_sent:diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.pyindex 90548543820..525e0078e6e 100644--- a/corporate/tests/test_stripe.py+++ b/corporate/tests/test_stripe.py@@ -10029,6 +10029,31 @@ class TestRemoteServerBillingFlow(StripeTestCase, RemoteServerTestCase):self.assertEqual(current_plan.next_invoice_date, updated_invoice_date)self.assertFalse(current_plan.stale_audit_log_data_email_sent)+ from django.core.mail import outbox++ message = outbox[-1]+ self.assert_length(message.to, 1)+ self.assertEqual(message.to[0], "[email protected]")+ self.assertEqual(+ message.subject,+ f"Stale audit log data for {self.billing_session.billing_entity_display_name}'s plan",+ )+ self.assertIn(+ f"Support URL: {self.billing_session.support_url()}",+ message.body,+ )+ self.assertIn(+ f"Internal billing notice for {self.billing_session.billing_entity_display_name}.",+ message.body,+ )+ self.assertIn(+ "Unable to verify current licenses in use, but invoicing not delayed because customer has a fixed-price plan.",+ message.body,+ )+ self.assertIn(+ f"Last data upload: {last_audit_log_update.strftime('%Y-%m-%d')}", message.body+ )+# Audit log data is up-to-date when the plan is next invoiced.with time_machine.travel(updated_invoice_date, tick=False):send_server_data_to_push_bouncer(consider_usage_statistics=False)diff --git a/templates/zerver/emails/internal_billing_notice.html b/templates/zerver/emails/internal_billing_notice.htmlindex 00f9010fe4d..9fd75b52640 100644--- a/templates/zerver/emails/internal_billing_notice.html+++ b/templates/zerver/emails/internal_billing_notice.html@@ -7,7 +7,11 @@{% if notice_reason == "fixed_price_plan_ends_soon" %}<p>Reminder to re-evaluate the pricing and configure a new fixed-price plan accordingly.</p>{% elif notice_reason == "stale_audit_log_data" %}+{% if fixed_price_plan %}+<p>Unable to verify current licenses in use, but invoicing not delayed because customer has a fixed-price plan.</p>+{% else %}<p>Unable to verify current licenses in use, which delays invoicing for this customer.</p>+{% endif %}<b>Last data upload</b>: {{ last_audit_log_update }}{% elif notice_reason == "locally_deleted_realm_on_paid_plan" %}<p>Investigate why remote realm is marked as locally deleted when it's on a paid plan.</p>diff --git a/templates/zerver/emails/internal_billing_notice.txt b/templates/zerver/emails/internal_billing_notice.txtindex 203275c6f98..6c26229ac3b 100644--- a/templates/zerver/emails/internal_billing_notice.txt+++ b/templates/zerver/emails/internal_billing_notice.txt@@ -3,9 +3,15 @@ Internal billing notice for {{ billing_entity }}.{% if notice_reason == "fixed_price_plan_ends_soon" %}Reminder to re-evaluate the pricing and configure a new fixed-price plan accordingly.{% elif notice_reason == "stale_audit_log_data" %}+{% if fixed_price_plan %}+Unable to verify current licenses in use, but invoicing not delayed because customer has a fixed-price plan.++Last data upload: {{ last_audit_log_update }}+{% else %}Unable to verify current licenses in use, which delays invoicing for this customer.Last data upload: {{ last_audit_log_update }}+{% endif %}{% elif notice_reason == "locally_deleted_realm_on_paid_plan" %}Investigate why remote realm is marked as locally deleted when it's on a paid plan.{% elif notice_reason == "license_discrepancy" %}