Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
billing: Add INVOICING_STATUS_ prefix to values.
Tim Abbottebb02bad8fe5
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex d81ad4ae722..ec810179bb2 100644--- a/corporate/lib/stripe.py+++ b/corporate/lib/stripe.py@@ -1128,7 +1128,7 @@ class BillingSession(ABC):status=CustomerPlan.FREE_TRIAL,next_invoice_date=next_billing_cycle,invoiced_through=None,- invoicing_status=CustomerPlan.INITIAL_INVOICE_TO_BE_SENT,+ invoicing_status=CustomerPlan.INVOICING_STATUS_INITIAL_INVOICE_TO_BE_SENT,)LicenseLedger.objects.create(@@ -1237,7 +1237,7 @@ class BillingSession(ABC):status=CustomerPlan.ACTIVE,next_invoice_date=next_billing_cycle,invoiced_through=None,- invoicing_status=CustomerPlan.INITIAL_INVOICE_TO_BE_SENT,+ invoicing_status=CustomerPlan.INVOICING_STATUS_INITIAL_INVOICE_TO_BE_SENT,)new_plan_ledger_entry = LicenseLedger.objects.create(@@ -1285,7 +1285,7 @@ class BillingSession(ABC):status=CustomerPlan.ACTIVE,next_invoice_date=next_billing_cycle,invoiced_through=None,- invoicing_status=CustomerPlan.INITIAL_INVOICE_TO_BE_SENT,+ invoicing_status=CustomerPlan.INVOICING_STATUS_INITIAL_INVOICE_TO_BE_SENT,)new_plan_ledger_entry = LicenseLedger.objects.create(@@ -1656,7 +1656,7 @@ class BillingSession(ABC):billing_schedule=current_plan.billing_schedule,tier=new_plan_tier,billing_cycle_anchor=new_plan_billing_cycle_anchor,- invoicing_status=CustomerPlan.INITIAL_INVOICE_TO_BE_SENT,+ invoicing_status=CustomerPlan.INVOICING_STATUS_INITIAL_INVOICE_TO_BE_SENT,next_invoice_date=new_plan_billing_cycle_anchor,)@@ -2839,7 +2839,7 @@ class PriceArgs(TypedDict, total=False):def invoice_plan(plan: CustomerPlan, event_time: datetime) -> None:- if plan.invoicing_status == CustomerPlan.STARTED:+ if plan.invoicing_status == CustomerPlan.INVOICING_STATUS_STARTED:raise NotImplementedError("Plan with invoicing_status==STARTED needs manual resolution.")if not plan.customer.stripe_customer_id:assert plan.customer.realm is not None@@ -2856,7 +2856,7 @@ def invoice_plan(plan: CustomerPlan, event_time: datetime) -> None:if plan.status is not CustomerPlan.SWITCH_PLAN_TIER_NOW:billing_session.make_end_of_cycle_updates_if_needed(plan, event_time)- if plan.invoicing_status == CustomerPlan.INITIAL_INVOICE_TO_BE_SENT:+ if plan.invoicing_status == CustomerPlan.INVOICING_STATUS_INITIAL_INVOICE_TO_BE_SENT:invoiced_through_id = -1licenses_base = Noneelse:@@ -2906,7 +2906,7 @@ def invoice_plan(plan: CustomerPlan, event_time: datetime) -> None:if price_args:plan.invoiced_through = ledger_entry- plan.invoicing_status = CustomerPlan.STARTED+ plan.invoicing_status = CustomerPlan.INVOICING_STATUS_STARTEDplan.save(update_fields=["invoicing_status", "invoiced_through"])stripe.InvoiceItem.create(currency="usd",@@ -2924,7 +2924,7 @@ def invoice_plan(plan: CustomerPlan, event_time: datetime) -> None:)invoice_item_created = Trueplan.invoiced_through = ledger_entry- plan.invoicing_status = CustomerPlan.DONE+ plan.invoicing_status = CustomerPlan.INVOICING_STATUS_DONEplan.save(update_fields=["invoicing_status", "invoiced_through"])licenses_base = ledger_entry.licensesdiff --git a/corporate/models.py b/corporate/models.pyindex 248955262d7..d06691ccc00 100644--- a/corporate/models.py+++ b/corporate/models.py@@ -248,13 +248,13 @@ class CustomerPlan(models.Model):)end_date = models.DateTimeField(null=True)- DONE = 1- STARTED = 2- INITIAL_INVOICE_TO_BE_SENT = 3+ INVOICING_STATUS_DONE = 1+ INVOICING_STATUS_STARTED = 2+ INVOICING_STATUS_INITIAL_INVOICE_TO_BE_SENT = 3# This status field helps ensure any errors encountered during the# invoicing process do not leave our invoicing system in a broken# state.- invoicing_status = models.SmallIntegerField(default=DONE)+ invoicing_status = models.SmallIntegerField(default=INVOICING_STATUS_DONE)TIER_CLOUD_STANDARD = 1TIER_CLOUD_PLUS = 2diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.pyindex e3f72bba7c2..13408a66824 100644--- a/corporate/tests/test_stripe.py+++ b/corporate/tests/test_stripe.py@@ -2372,7 +2372,9 @@ class StripeTest(StripeTestCase):assert annual_plan is not Noneself.assertEqual(annual_plan.status, CustomerPlan.ACTIVE)self.assertEqual(annual_plan.billing_schedule, CustomerPlan.BILLING_SCHEDULE_ANNUAL)- self.assertEqual(annual_plan.invoicing_status, CustomerPlan.INITIAL_INVOICE_TO_BE_SENT)+ self.assertEqual(+ annual_plan.invoicing_status, CustomerPlan.INVOICING_STATUS_INITIAL_INVOICE_TO_BE_SENT+ )self.assertEqual(annual_plan.billing_cycle_anchor, self.next_month)self.assertEqual(annual_plan.next_invoice_date, self.next_month)self.assertEqual(annual_plan.invoiced_through, None)@@ -2398,7 +2400,7 @@ class StripeTest(StripeTestCase):annual_ledger_entries = LicenseLedger.objects.filter(plan=annual_plan).order_by("id")self.assert_length(annual_ledger_entries, 2)annual_plan.refresh_from_db()- self.assertEqual(annual_plan.invoicing_status, CustomerPlan.DONE)+ self.assertEqual(annual_plan.invoicing_status, CustomerPlan.INVOICING_STATUS_DONE)self.assertEqual(annual_plan.invoiced_through, annual_ledger_entries[1])self.assertEqual(annual_plan.billing_cycle_anchor, self.next_month)self.assertEqual(annual_plan.next_invoice_date, add_months(self.next_month, 1))@@ -2552,7 +2554,9 @@ class StripeTest(StripeTestCase):assert annual_plan is not Noneself.assertEqual(annual_plan.status, CustomerPlan.ACTIVE)self.assertEqual(annual_plan.billing_schedule, CustomerPlan.BILLING_SCHEDULE_ANNUAL)- self.assertEqual(annual_plan.invoicing_status, CustomerPlan.INITIAL_INVOICE_TO_BE_SENT)+ self.assertEqual(+ annual_plan.invoicing_status, CustomerPlan.INVOICING_STATUS_INITIAL_INVOICE_TO_BE_SENT+ )self.assertEqual(annual_plan.billing_cycle_anchor, self.next_month)self.assertEqual(annual_plan.next_invoice_date, self.next_month)annual_ledger_entries = LicenseLedger.objects.filter(plan=annual_plan).order_by("id")@@ -2571,7 +2575,7 @@ class StripeTest(StripeTestCase):annual_plan.refresh_from_db()self.assertEqual(annual_plan.invoiced_through, annual_ledger_entries[0])self.assertEqual(annual_plan.next_invoice_date, add_months(self.next_month, 12))- self.assertEqual(annual_plan.invoicing_status, CustomerPlan.DONE)+ self.assertEqual(annual_plan.invoicing_status, CustomerPlan.INVOICING_STATUS_DONE)assert customer.stripe_customer_id[invoice0, invoice1] = iter(stripe.Invoice.list(customer=customer.stripe_customer_id))@@ -2680,7 +2684,7 @@ class StripeTest(StripeTestCase):annual_plan.refresh_from_db()self.assertEqual(annual_plan.next_invoice_date, add_months(self.next_month, 1))- self.assertEqual(annual_plan.invoicing_status, CustomerPlan.DONE)+ self.assertEqual(annual_plan.invoicing_status, CustomerPlan.INVOICING_STATUS_DONE)self.assertEqual(LicenseLedger.objects.filter(plan=annual_plan).count(), 3)customer = get_customer_by_realm(user.realm)@@ -2734,7 +2738,9 @@ class StripeTest(StripeTestCase):assert monthly_plan is not Noneself.assertEqual(monthly_plan.status, CustomerPlan.ACTIVE)self.assertEqual(monthly_plan.billing_schedule, CustomerPlan.BILLING_SCHEDULE_MONTHLY)- self.assertEqual(monthly_plan.invoicing_status, CustomerPlan.INITIAL_INVOICE_TO_BE_SENT)+ self.assertEqual(+ monthly_plan.invoicing_status, CustomerPlan.INVOICING_STATUS_INITIAL_INVOICE_TO_BE_SENT+ )self.assertEqual(monthly_plan.billing_cycle_anchor, self.next_year)self.assertEqual(monthly_plan.next_invoice_date, self.next_year)self.assertEqual(monthly_plan.invoiced_through, None)@@ -2760,7 +2766,7 @@ class StripeTest(StripeTestCase):monthly_ledger_entries = LicenseLedger.objects.filter(plan=monthly_plan).order_by("id")self.assert_length(monthly_ledger_entries, 2)monthly_plan.refresh_from_db()- self.assertEqual(monthly_plan.invoicing_status, CustomerPlan.DONE)+ self.assertEqual(monthly_plan.invoicing_status, CustomerPlan.INVOICING_STATUS_DONE)self.assertEqual(monthly_plan.invoiced_through, monthly_ledger_entries[1])self.assertEqual(monthly_plan.billing_cycle_anchor, self.next_year)self.assertEqual(monthly_plan.next_invoice_date, add_months(self.next_year, 1))@@ -4827,7 +4833,7 @@ class InvoiceTest(StripeTestCase):self.local_upgrade(self.seat_count, True, CustomerPlan.BILLING_SCHEDULE_ANNUAL, True, False)plan = CustomerPlan.objects.first()assert plan is not None- plan.invoicing_status = CustomerPlan.STARTED+ plan.invoicing_status = CustomerPlan.INVOICING_STATUS_STARTEDplan.save(update_fields=["invoicing_status"])with self.assertRaises(NotImplementedError):invoice_plan(assert_is_not_none(CustomerPlan.objects.first()), self.now)