diff --git a/core/management/commands/populate_more.py b/core/management/commands/populate_more.py index 3262fe46..544be7c1 100644 --- a/core/management/commands/populate_more.py +++ b/core/management/commands/populate_more.py @@ -144,10 +144,22 @@ class Command(BaseCommand): ) def create_subscriptions(self, users: list[User]): + subscription_types = [ + "un-semestre", + "deux-semestres", + "cursus-tronc-commun", + "cursus-branche", + ] + def prepare_subscription(_user: User, start_date: date) -> Subscription: payment_method = random.choice(settings.SITH_SUBSCRIPTION_PAYMENT_METHOD)[0] - duration = random.randint(1, 4) - s = Subscription(member=_user, payment_method=payment_method) + subscription_type = random.choice(subscription_types) + s = Subscription( + member=_user, + payment_method=payment_method, + subscription_type=subscription_type, + ) + duration = settings.SITH_SUBSCRIPTIONS[subscription_type]["duration"] s.subscription_start = s.compute_start(d=start_date, duration=duration) s.subscription_end = s.compute_end(duration) return s diff --git a/subscription/forms.py b/subscription/forms.py index 7f8cd7d7..29a70b8d 100644 --- a/subscription/forms.py +++ b/subscription/forms.py @@ -8,22 +8,11 @@ from django.utils.translation import gettext_lazy as _ from core.models import User from core.utils import get_last_promo -from core.views.forms import SelectDate, SelectDateTime +from core.views.forms import SelectDate from core.views.widgets.ajax_select import AutoCompleteSelectUser from subscription.models import Subscription -class SelectionDateForm(forms.Form): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.fields["start_date"] = forms.DateTimeField( - label=_("Start date"), widget=SelectDateTime, required=True - ) - self.fields["end_date"] = forms.DateTimeField( - label=_("End date"), widget=SelectDateTime, required=True - ) - - class SubscriptionForm(forms.ModelForm): allowed_payment_methods = ["CARD", "CASH", "AE_ACCOUNT"] diff --git a/subscription/static/bundled/subscription/stats-index.ts b/subscription/static/bundled/subscription/stats-index.ts index 3fc992b3..fef50d1b 100644 --- a/subscription/static/bundled/subscription/stats-index.ts +++ b/subscription/static/bundled/subscription/stats-index.ts @@ -1,6 +1,13 @@ -import { BarController, BarElement, CategoryScale, Chart, LinearScale } from "chart.js"; +import { + BarController, + BarElement, + CategoryScale, + Chart, + LinearScale, + Tooltip, +} from "chart.js"; -Chart.register(BarController, BarElement, CategoryScale, LinearScale); +Chart.register(BarController, BarElement, CategoryScale, LinearScale, Tooltip); function getRandomColor() { const letters = "0123456789ABCDEF"; diff --git a/subscription/templates/subscription/stats.jinja b/subscription/templates/subscription/stats.jinja index eb124032..a1dd22d0 100644 --- a/subscription/templates/subscription/stats.jinja +++ b/subscription/templates/subscription/stats.jinja @@ -11,51 +11,39 @@ {% block content %} -
-
- - -
- {% trans %}Total subscriptions{% endtrans %} : {{ subscriptions_total.count() }}
- {% trans %}Subscriptions by type{% endtrans %}
- {% for location in locations %}
- {{ location[1] }} : {{ subscriptions_total.filter(location=location[0]).count() }}
+
+
| {% trans %}Subscription type{% endtrans %} | + {% for location in locations %} +{{ location[1] }} | + {% endfor %} +{% trans %}Total{% endtrans %} | + +
|---|---|---|
| {% trans %}All subscriptions{% endtrans %} | + {% for location in locations %} +{{ total_location[location[0]] }} |
+ {% endfor %}
+ {{ total_location.values()|sum }} | +
| {{ subscriptions_types[type]['name'] }} | + {% for location in locations %} +
+ {% for p_type in payment_types %}
+ {% set subtotal = subscriptions[type][location[0]][p_type[0]] %}
+ {% if subtotal > 0 %}
+ {{ p_type[1] }} : {{ subtotal }} + {% endif %} + {% endfor %} + |
+ {% endfor %}
+ {{ total_type[type] }} | +
| {% trans %}Subscription type{% endtrans %} | - {% for location in locations %} -{{ location[1] }} | - {% endfor %} -{% trans %}Total{% endtrans %} | - {% for type in subscriptions_types %} -
|---|---|---|
| {{ subscriptions_types[type]['name'] }} | - {% set subscriptions_total_type = subscriptions_total.filter(subscription_type=type) %} - {% for location in locations %} -
- {% set subscriptions_total_type_location = subscriptions_total_type.filter(location=location[0]) %}
- {% trans %}Total{% endtrans %} : {{ subscriptions_total_type_location.count()}} - {% for p_type in payment_types %} - {{ p_type[1] }} : {{ subscriptions_total_type_location.filter(payment_method=p_type[0]).count()}} - {% endfor %} - |
- {% endfor %}
- {{subscriptions_total_type.count()}} - |