mirror of https://github.com/zulip/zulip.git
billing: Extract get_seat_count function.
This is a simple generalization of get_latest_seat_count and is useful for calculating "what will be the realm's license count if this number of (guest) users is added?" without duplicating any of the math logic. Will be used in the next commits.
This commit is contained in:
parent
6582a002e7
commit
a41cecb695
|
@ -58,14 +58,23 @@ STRIPE_API_VERSION = "2020-08-27"
|
||||||
|
|
||||||
|
|
||||||
def get_latest_seat_count(realm: Realm) -> int:
|
def get_latest_seat_count(realm: Realm) -> int:
|
||||||
|
return get_seat_count(realm, extra_non_guests_count=0, extra_guests_count=0)
|
||||||
|
|
||||||
|
|
||||||
|
def get_seat_count(
|
||||||
|
realm: Realm, extra_non_guests_count: int = 0, extra_guests_count: int = 0
|
||||||
|
) -> int:
|
||||||
non_guests = (
|
non_guests = (
|
||||||
UserProfile.objects.filter(realm=realm, is_active=True, is_bot=False)
|
UserProfile.objects.filter(realm=realm, is_active=True, is_bot=False)
|
||||||
.exclude(role=UserProfile.ROLE_GUEST)
|
.exclude(role=UserProfile.ROLE_GUEST)
|
||||||
.count()
|
.count()
|
||||||
)
|
) + extra_non_guests_count
|
||||||
guests = UserProfile.objects.filter(
|
guests = (
|
||||||
|
UserProfile.objects.filter(
|
||||||
realm=realm, is_active=True, is_bot=False, role=UserProfile.ROLE_GUEST
|
realm=realm, is_active=True, is_bot=False, role=UserProfile.ROLE_GUEST
|
||||||
).count()
|
).count()
|
||||||
|
+ extra_guests_count
|
||||||
|
)
|
||||||
|
|
||||||
# This formula achieves the pricing of the first 5*N guests
|
# This formula achieves the pricing of the first 5*N guests
|
||||||
# being free of charge (where N is the number of non-guests in the organization)
|
# being free of charge (where N is the number of non-guests in the organization)
|
||||||
|
|
Loading…
Reference in New Issue