mirror of
				https://github.com/zulip/zulip.git
				synced 2025-10-30 19:43:47 +00:00 
			
		
		
		
	billing: Add INVOICING_STATUS_ prefix to values.
This commit is contained in:
		| @@ -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 = -1 | ||||
|         licenses_base = None | ||||
|     else: | ||||
| @@ -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_STARTED | ||||
|             plan.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 = True | ||||
|         plan.invoiced_through = ledger_entry | ||||
|         plan.invoicing_status = CustomerPlan.DONE | ||||
|         plan.invoicing_status = CustomerPlan.INVOICING_STATUS_DONE | ||||
|         plan.save(update_fields=["invoicing_status", "invoiced_through"]) | ||||
|         licenses_base = ledger_entry.licenses | ||||
|  | ||||
|   | ||||
| @@ -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 = 1 | ||||
|     TIER_CLOUD_PLUS = 2 | ||||
|   | ||||
| @@ -2372,7 +2372,9 @@ class StripeTest(StripeTestCase): | ||||
|         assert annual_plan is not None | ||||
|         self.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 None | ||||
|         self.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 None | ||||
|         self.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_STARTED | ||||
|         plan.save(update_fields=["invoicing_status"]) | ||||
|         with self.assertRaises(NotImplementedError): | ||||
|             invoice_plan(assert_is_not_none(CustomerPlan.objects.first()), self.now) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user