24 lines
814 B
Python
24 lines
814 B
Python
from django.core.exceptions import ValidationError
|
|
from plans.quota import get_user_quota
|
|
|
|
|
|
class DealerStaffQuotaValidator:
|
|
"""
|
|
Validator to ensure a Dealer cannot add more than the allowed number of Staff members.
|
|
"""
|
|
|
|
def __init__(self, quota_name='Users'):
|
|
self.quota_name = quota_name
|
|
|
|
def __call__(self, dealer):
|
|
# Get the quota for the dealer's plan
|
|
quota_limit = get_user_quota(dealer.user, self.quota_name)
|
|
|
|
# Count the number of staff members associated with the dealer
|
|
staff_count = dealer.staff.count()
|
|
|
|
# Check if the quota is exceeded
|
|
if staff_count >= quota_limit:
|
|
raise ValidationError(
|
|
f"You have reached the maximum number of staff members ({quota_limit}) allowed by your plan."
|
|
) |