mirror of
https://github.com/ae-utbm/sith.git
synced 2026-09-22 12:14:22 +00:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7fdb1a914f | ||
|
|
130afc471c | ||
|
|
e937189b80 | ||
|
|
9b8ca76e33 | ||
|
|
aedfbf948e | ||
|
|
8175fc415c |
@@ -138,10 +138,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
|
||||
|
||||
@@ -123,14 +123,14 @@ document.addEventListener("alpine:init", () => {
|
||||
|
||||
onRefillingSuccess(event: CustomEvent) {
|
||||
if (
|
||||
event.type !== "htmx:after-swap" ||
|
||||
event.detail.failed ||
|
||||
event.detail.elt.querySelector(".errorlist")
|
||||
event.type !== "htmx:after:swap" ||
|
||||
event.detail.ctx.response.status !== 200 ||
|
||||
event.detail.ctx.target.querySelector(".errorlist")
|
||||
) {
|
||||
return;
|
||||
}
|
||||
this.customerBalance += Number.parseFloat(
|
||||
(event.detail.target.querySelector("#id_amount") as HTMLInputElement).value,
|
||||
(event.detail.ctx.target.querySelector("#id_amount") as HTMLInputElement).value,
|
||||
);
|
||||
document.getElementById("selling-accordion")?.setAttribute("open", "");
|
||||
this.codeField?.widget.focus();
|
||||
|
||||
@@ -62,8 +62,7 @@
|
||||
}
|
||||
|
||||
form {
|
||||
margin-top: .5rem;
|
||||
margin-bottom: .5rem;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@
|
||||
{% if refilling_fragment %}
|
||||
<div
|
||||
class="accordion-content"
|
||||
@htmx:after-swap="onRefillingSuccess"
|
||||
@htmx:after:swap="onRefillingSuccess"
|
||||
>
|
||||
{{ refilling_fragment }}
|
||||
</div>
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
hx-swap="outerHTML"
|
||||
>
|
||||
{% csrf_token %}
|
||||
<div class="margin-bottom">
|
||||
{{ form.as_p() }}
|
||||
<input type="submit" value="{% trans %}Go{% endtrans %}"/>
|
||||
</div>
|
||||
<input type="submit" class="btn btn-blue" value="{% trans %}Go{% endtrans %}"/>
|
||||
</form>
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
</p>
|
||||
<br>
|
||||
{% if settings.SITH_EBOUTIC_CB_ENABLED %}
|
||||
<div @htmx:after-request="fill">
|
||||
<div @htmx:after:request="fill">
|
||||
{{ billing_infos_form }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
+1
-12
@@ -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"]
|
||||
|
||||
|
||||
@@ -11,35 +11,23 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
<p>
|
||||
<form>
|
||||
{{ form.start_date.label }}<br>
|
||||
{{ form.start_date }}<br><br>
|
||||
{{ form.end_date.label }}<br>
|
||||
{{ form.end_date }}<br>
|
||||
<p><input type="submit" value="{% trans %}Go{% endtrans %}" /></p>
|
||||
</form>
|
||||
</p>
|
||||
|
||||
<canvas id="statsChart" width="400" height="200"></canvas>
|
||||
|
||||
<p>
|
||||
{% trans %}Total subscriptions{% endtrans %} : {{ subscriptions_total.count() }}<br><br>
|
||||
{% trans %}Subscriptions by type{% endtrans %}<br><br>
|
||||
{% for location in locations %}
|
||||
{{ location[1] }} : <i class="nb">{{ subscriptions_total.filter(location=location[0]).count() }}</i><br>
|
||||
{% endfor %}
|
||||
<p>
|
||||
|
||||
<br>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<thead>
|
||||
<th>{% trans %}Subscription type{% endtrans %}</th>
|
||||
{% for location in locations %}
|
||||
<th>{{ location[1] }}</th>
|
||||
{% endfor %}
|
||||
<th id="graphLabel">{% trans %}Total{% endtrans %}</th>
|
||||
</thead>
|
||||
{% for type in subscriptions_types %}
|
||||
<tr>
|
||||
<td><i class="types" >{{ subscriptions_types[type]['name'] }}</i></td>
|
||||
@@ -53,9 +41,8 @@
|
||||
{% endfor %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
<td class="total"><i class="nb">{{subscriptions_total_type.count()}}</i>
|
||||
<td class="total"><i class="nb">{{subscriptions_total_type.count()}}</i></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
+4
-21
@@ -17,16 +17,14 @@ from django.conf import settings
|
||||
from django.contrib.auth.forms import PasswordResetForm
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.urls import reverse
|
||||
from django.utils.timezone import localdate
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import CreateView, DetailView, TemplateView
|
||||
from django.views.generic.edit import FormView
|
||||
|
||||
from core.views import FragmentMixin, UseFragmentsMixin
|
||||
from core.views.group import PermissionGroupsUpdateView
|
||||
from subscription.forms import (
|
||||
SelectionDateForm,
|
||||
SubscriptionExistingUserForm,
|
||||
SubscriptionNewUserForm,
|
||||
)
|
||||
@@ -93,34 +91,19 @@ class SubscriptionPermissionView(PermissionGroupsUpdateView):
|
||||
extra_context = {"object_name": _("the groups that can create subscriptions")}
|
||||
|
||||
|
||||
class SubscriptionsStatsView(FormView):
|
||||
class SubscriptionsStatsView(TemplateView):
|
||||
template_name = "subscription/stats.jinja"
|
||||
form_class = SelectionDateForm
|
||||
success_url = reverse_lazy("subscriptions:stats")
|
||||
|
||||
def dispatch(self, request, *arg, **kwargs):
|
||||
self.start_date = localdate()
|
||||
self.end_date = self.start_date
|
||||
if request.user.is_root or request.user.is_board_member:
|
||||
return super().dispatch(request, *arg, **kwargs)
|
||||
raise PermissionDenied
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.form = self.get_form()
|
||||
self.start_date = self.form["start_date"]
|
||||
self.end_date = self.form["end_date"]
|
||||
return super().post(request, *args, **kwargs)
|
||||
|
||||
def get_initial(self):
|
||||
return {
|
||||
"start_date": self.start_date.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
"end_date": self.end_date.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
}
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super().get_context_data(**kwargs)
|
||||
today = localdate()
|
||||
kwargs["subscriptions_total"] = Subscription.objects.filter(
|
||||
subscription_end__gte=self.end_date, subscription_start__lte=self.start_date
|
||||
subscription_end__gte=today, subscription_start__lte=today
|
||||
)
|
||||
kwargs["subscriptions_types"] = settings.SITH_SUBSCRIPTIONS
|
||||
kwargs["payment_types"] = settings.SITH_SUBSCRIPTION_PAYMENT_METHOD
|
||||
|
||||
Reference in New Issue
Block a user