Skip to content

Commit c7a0831

Browse files
fix: Fix children courses remaining capacity
1 parent 94316cb commit c7a0831

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

mono/presentations/models.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,19 @@ def save(self, *args, **kwargs):
5858
return super().save(*args, **kwargs)
5959

6060
def remained_capacity(self) -> int:
61-
"""
62-
For single-object usage.
63-
Prefer `Course.objects.with_capacity()` when listing many courses.
64-
"""
65-
counted_status = Registration.Status.FINAL # <- adjust here if your “counted” state changes
66-
finalized = self.registrations.filter(status=counted_status).count()
67-
# Never negative:
68-
return max(self.capacity - finalized, 0)
61+
from .models import Registration # local import to avoid cycles
62+
63+
finalized_as_parent = self.registrations.filter(
64+
status=Registration.Status.FINAL
65+
).count()
66+
67+
finalized_as_child = self.registration_items.filter(
68+
registration__status=Registration.Status.FINAL
69+
).count()
70+
71+
used = finalized_as_parent + finalized_as_child
72+
cap = self.capacity or 0
73+
return max(cap - used, 0)
6974

7075
def __str__(self):
7176
return self.name

0 commit comments

Comments
 (0)