feat: add Usage Limits Panel component with usage tracking and visual indicators for limits
style: implement custom color schemes and gradients for account section, enhancing visual hierarchy
This commit is contained in:
@@ -189,6 +189,83 @@ class CreditCostConfig(models.Model):
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
class PlanLimitUsage(AccountBaseModel):
|
||||
"""
|
||||
Track monthly usage of plan limits (ideas, words, images, prompts)
|
||||
Resets at start of each billing period
|
||||
"""
|
||||
LIMIT_TYPE_CHOICES = [
|
||||
('content_ideas', 'Content Ideas'),
|
||||
('content_words', 'Content Words'),
|
||||
('images_basic', 'Basic Images'),
|
||||
('images_premium', 'Premium Images'),
|
||||
('image_prompts', 'Image Prompts'),
|
||||
]
|
||||
|
||||
limit_type = models.CharField(
|
||||
max_length=50,
|
||||
choices=LIMIT_TYPE_CHOICES,
|
||||
db_index=True,
|
||||
help_text="Type of limit being tracked"
|
||||
)
|
||||
amount_used = models.IntegerField(
|
||||
default=0,
|
||||
validators=[MinValueValidator(0)],
|
||||
help_text="Amount used in current period"
|
||||
)
|
||||
|
||||
# Billing period tracking
|
||||
period_start = models.DateField(
|
||||
help_text="Start date of billing period"
|
||||
)
|
||||
period_end = models.DateField(
|
||||
help_text="End date of billing period"
|
||||
)
|
||||
|
||||
# Metadata
|
||||
metadata = models.JSONField(
|
||||
default=dict,
|
||||
blank=True,
|
||||
help_text="Additional tracking data (e.g., breakdown by site)"
|
||||
)
|
||||
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
app_label = 'billing'
|
||||
db_table = 'igny8_plan_limit_usage'
|
||||
verbose_name = 'Plan Limit Usage'
|
||||
verbose_name_plural = 'Plan Limit Usage Records'
|
||||
unique_together = [['account', 'limit_type', 'period_start']]
|
||||
ordering = ['-period_start', 'limit_type']
|
||||
indexes = [
|
||||
models.Index(fields=['account', 'limit_type']),
|
||||
models.Index(fields=['account', 'period_start', 'period_end']),
|
||||
models.Index(fields=['limit_type', 'period_start']),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
account = getattr(self, 'account', None)
|
||||
return f"{account.name if account else 'No Account'} - {self.get_limit_type_display()} - {self.amount_used} used"
|
||||
|
||||
def is_current_period(self):
|
||||
"""Check if this record is for the current billing period"""
|
||||
from django.utils import timezone
|
||||
today = timezone.now().date()
|
||||
return self.period_start <= today <= self.period_end
|
||||
|
||||
def remaining_allowance(self, plan_limit):
|
||||
"""Calculate remaining allowance"""
|
||||
return max(0, plan_limit - self.amount_used)
|
||||
|
||||
def percentage_used(self, plan_limit):
|
||||
"""Calculate percentage of limit used"""
|
||||
if plan_limit == 0:
|
||||
return 0
|
||||
return min(100, int((self.amount_used / plan_limit) * 100))
|
||||
|
||||
|
||||
class Invoice(AccountBaseModel):
|
||||
"""
|
||||
Invoice for subscription or credit purchases
|
||||
|
||||
Reference in New Issue
Block a user