billing: Move exempt_from_from_license_number_check to Customer model.

This belongs more on the Customer model, since this is a similar
attribute to default_discount.
This commit is contained in:
Mateusz Mandera 2021-06-18 20:43:30 +02:00 committed by Tim Abbott
parent 4ca87d785b
commit bae86ad3da
3 changed files with 35 additions and 5 deletions

View File

@ -72,7 +72,11 @@ def check_spare_licenses_available_for_adding_new_users(
realm: Realm, number_of_users_to_add: int
) -> None:
plan = get_current_plan_by_realm(realm)
if plan is None or plan.automanage_licenses or plan.exempt_from_from_license_number_check:
if (
plan is None
or plan.automanage_licenses
or plan.customer.exempt_from_from_license_number_check
):
return
if plan.licenses() < get_latest_seat_count(realm) + number_of_users_to_add:

View File

@ -0,0 +1,27 @@
# Generated by Django 3.2.4 on 2021-06-18 18:39
from django.db import migrations, models
class Migration(migrations.Migration):
"""
We haven't set the values for this field for the relevant organizations
as of this moment, so we can simply drop the column from CustomerPlan
and add it to Customer without worrying about losing the values.
"""
dependencies = [
("corporate", "0010_customerplan_exempt_from_from_license_number_check"),
]
operations = [
migrations.RemoveField(
model_name="customerplan",
name="exempt_from_from_license_number_check",
),
migrations.AddField(
model_name="customer",
name="exempt_from_from_license_number_check",
field=models.BooleanField(default=False),
),
]

View File

@ -22,6 +22,9 @@ class Customer(models.Model):
default_discount: Optional[Decimal] = models.DecimalField(
decimal_places=4, max_digits=7, null=True
)
# Some non-profit organizations on manual license management pay only for their paid employees.
# We don't prevent these organizations from adding more users than the number of licenses they purchased.
exempt_from_from_license_number_check: bool = models.BooleanField(default=False)
def __str__(self) -> str:
return f"<Customer {self.realm} {self.stripe_customer_id}>"
@ -45,10 +48,6 @@ class CustomerPlan(models.Model):
automanage_licenses: bool = models.BooleanField(default=False)
charge_automatically: bool = models.BooleanField(default=False)
# Some non-profit organizations on manual license management pay only for their paid employees.
# We don't prevent these organizations from adding more users than the number of licenses they purchased.
exempt_from_from_license_number_check: bool = models.BooleanField(default=False)
# Both of these are in cents. Exactly one of price_per_license or
# fixed_price should be set. fixed_price is only for manual deals, and
# can't be set via the self-serve billing system.