corporate: Exclude non-realm Customer objects in downgrade small realms.

Updates query in downgrade_small_realms_behind_on_payments_as_needed
to exclude Customer objects with realm=None.
This commit is contained in:
Lauryn Menard
2023-10-30 16:28:52 +01:00
committed by Tim Abbott
parent c996bb3c19
commit 37b70a8e24
2 changed files with 10 additions and 1 deletions

View File

@@ -1116,7 +1116,7 @@ def customer_has_last_n_invoices_open(customer: Customer, n: int) -> bool:
def downgrade_small_realms_behind_on_payments_as_needed() -> None:
customers = Customer.objects.all().exclude(stripe_customer_id=None)
customers = Customer.objects.all().exclude(stripe_customer_id=None).exclude(realm=None)
for customer in customers:
realm = customer.realm
assert realm is not None

View File

@@ -3789,6 +3789,15 @@ class StripeTest(StripeTestCase):
)
rows.append(Row(realm, Realm.PLAN_TYPE_STANDARD, plan, CustomerPlan.ACTIVE, False, False))
# Customer objects without a realm should be excluded from query.
remote_server = RemoteZulipServer.objects.create(
uuid=str(uuid.uuid4()),
api_key="magic_secret_api_key",
hostname="demo.example.com",
contact_email="email@example.com",
)
Customer.objects.create(remote_server=remote_server, stripe_customer_id="cus_xxx")
with patch("corporate.lib.stripe.void_all_open_invoices") as void_all_open_invoices_mock:
downgrade_small_realms_behind_on_payments_as_needed()