mirror of
https://github.com/zulip/zulip.git
synced 2025-10-31 20:13:46 +00:00
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:
committed by
Tim Abbott
parent
c996bb3c19
commit
37b70a8e24
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user