feat(events): harden registration checkout lifecycle

This commit is contained in:
2026-10-01 12:26:49 +03:30
parent 1daa755543
commit 962238c32c
29 changed files with 3048 additions and 207 deletions

View File

@@ -108,8 +108,15 @@ class Event(BaseModel):
@property
def current_attendees_count(self):
"""Count confirmed attendees"""
return self.registrations.filter(status__in=[Registration.StatusChoices.CONFIRMED, Registration.StatusChoices.ATTENDED], is_deleted=False).count()
"""Count confirmed attendees and currently held paid-checkout seats."""
now = timezone.now()
return self.registrations.filter(is_deleted=False).filter(
models.Q(status__in=[Registration.StatusChoices.CONFIRMED, Registration.StatusChoices.ATTENDED])
| models.Q(
status=Registration.StatusChoices.PENDING,
checkout_expires_at__gt=now,
)
).count()
@property
def has_available_slots(self):
@@ -132,9 +139,24 @@ class Registration(BaseModel):
SYSTEM = 'system', 'System'
HISTORICAL = 'historical', 'Historical backfill'
class CancellationReasonChoices(models.TextChoices):
CHECKOUT_EXPIRED = 'checkout_expired', 'Checkout expired'
USER_CANCELLED = 'user_cancelled', 'User cancelled checkout'
EVENT_CANCELLED = 'event_cancelled', 'Event cancelled'
PAYMENT_FAILED = 'payment_failed', 'Payment failed'
event = models.ForeignKey(Event, on_delete=models.CASCADE, related_name='registrations')
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='event_registrations')
registered_at = models.DateTimeField(auto_now_add=True)
checkout_started_at = models.DateTimeField(null=True, blank=True, editable=False)
checkout_expires_at = models.DateTimeField(null=True, blank=True, editable=False)
cancellation_reason = models.CharField(
max_length=32,
choices=CancellationReasonChoices.choices,
blank=True,
default='',
editable=False,
)
status = models.CharField(max_length=10, choices=StatusChoices.choices,
default=StatusChoices.PENDING)
attendance_verified_at = models.DateTimeField(null=True, blank=True)