Allow filtering of refilling options

* Move settings.SITH_COUNTER_PAYMENT_METHOD to counter.apps.PAYMENT_METHOD
* Move student cards to an accordion on counter click
* Make cash default refilling option
* Disable bank selection option in refilling if CHECK are not allowed
* Disable refilling with CHECK from the frontend
This commit is contained in:
Antoine Bartuccio 2024-12-16 00:15:21 +01:00
parent cde864fdc7
commit f63fb59cbf
9 changed files with 260 additions and 215 deletions

View File

@ -24,6 +24,12 @@
from django.apps import AppConfig from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
PAYMENT_METHOD = [
("CHECK", _("Check")),
("CASH", _("Cash")),
("CARD", _("Credit card")),
]
class CounterConfig(AppConfig): class CounterConfig(AppConfig):
name = "counter" name = "counter"

View File

@ -111,6 +111,8 @@ class GetUserForm(forms.Form):
class RefillForm(forms.ModelForm): class RefillForm(forms.ModelForm):
allowed_refilling_methods = ["CASH", "CARD"]
error_css_class = "error" error_css_class = "error"
required_css_class = "required" required_css_class = "required"
amount = forms.FloatField( amount = forms.FloatField(
@ -120,6 +122,21 @@ class RefillForm(forms.ModelForm):
class Meta: class Meta:
model = Refilling model = Refilling
fields = ["amount", "payment_method", "bank"] fields = ["amount", "payment_method", "bank"]
widgets = {"payment_method": forms.RadioSelect}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["payment_method"].choices = (
method
for method in self.fields["payment_method"].choices
if method[0] in self.allowed_refilling_methods
)
if self.fields["payment_method"].initial not in self.allowed_refilling_methods:
self.fields["payment_method"].initial = self.allowed_refilling_methods[0]
if "CHECK" not in self.allowed_refilling_methods:
del self.fields["bank"]
class CounterEditForm(forms.ModelForm): class CounterEditForm(forms.ModelForm):

View File

@ -0,0 +1,22 @@
# Generated by Django 4.2.17 on 2024-12-15 22:21
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("counter", "0026_alter_studentcard_customer"),
]
operations = [
migrations.AlterField(
model_name="refilling",
name="payment_method",
field=models.CharField(
choices=[("CHECK", "Check"), ("CASH", "Cash"), ("CARD", "Credit card")],
default="CARD",
max_length=255,
verbose_name="payment method",
),
),
]

View File

@ -42,6 +42,7 @@ from club.models import Club
from core.fields import ResizedImageField from core.fields import ResizedImageField
from core.models import Group, Notification, User from core.models import Group, Notification, User
from core.utils import get_start_of_semester from core.utils import get_start_of_semester
from counter.apps import PAYMENT_METHOD
from sith.settings import SITH_COUNTER_OFFICES, SITH_MAIN_CLUB from sith.settings import SITH_COUNTER_OFFICES, SITH_MAIN_CLUB
from subscription.models import Subscription from subscription.models import Subscription
@ -697,8 +698,8 @@ class Refilling(models.Model):
payment_method = models.CharField( payment_method = models.CharField(
_("payment method"), _("payment method"),
max_length=255, max_length=255,
choices=settings.SITH_COUNTER_PAYMENT_METHOD, choices=PAYMENT_METHOD,
default="CASH", default="CARD",
) )
bank = models.CharField( bank = models.CharField(
_("bank"), max_length=255, choices=settings.SITH_COUNTER_BANK, default="OTHER" _("bank"), max_length=255, choices=settings.SITH_COUNTER_BANK, default="OTHER"

View File

@ -29,11 +29,6 @@
{{ user_mini_profile(customer.user) }} {{ user_mini_profile(customer.user) }}
{{ user_subscription(customer.user) }} {{ user_subscription(customer.user) }}
<p>{% trans %}Amount: {% endtrans %}<span x-text="customerBalance"></span> €</p> <p>{% trans %}Amount: {% endtrans %}<span x-text="customerBalance"></span> €</p>
{% if counter.type == 'BAR' %}
<h5>{% trans %}Student card{% endtrans %}</h3>
{{ student_card_fragment }}
{% endif %}
</div> </div>
<div id="click_form"> <div id="click_form">
@ -113,6 +108,12 @@
{{ refilling_fragment }} {{ refilling_fragment }}
</div> </div>
{% endif %} {% endif %}
{% if student_card_fragment %}
<h5>{% trans %}Student card{% endtrans %}</h3>
<div>
{{ student_card_fragment }}
</div>
{% endif %}
</div> </div>
<div id="products"> <div id="products">

View File

@ -394,6 +394,8 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView):
) )
kwargs["customer"] = self.customer kwargs["customer"] = self.customer
kwargs["basket_total"] = self.sum_basket(self.request) kwargs["basket_total"] = self.sum_basket(self.request)
if self.object.type == "BAR":
kwargs["student_card_fragment"] = StudentCardFormView.get_template_data( kwargs["student_card_fragment"] = StudentCardFormView.get_template_data(
self.customer self.customer
).render(self.request) ).render(self.request)

File diff suppressed because it is too large Load Diff

View File

@ -434,12 +434,6 @@ SITH_COUNTER_BARS = [(1, "MDE"), (2, "Foyer"), (35, "La Gommette")]
SITH_COUNTER_OFFICES = {2: "PdF", 1: "AE"} SITH_COUNTER_OFFICES = {2: "PdF", 1: "AE"}
SITH_COUNTER_PAYMENT_METHOD = [
("CHECK", _("Check")),
("CASH", _("Cash")),
("CARD", _("Credit card")),
]
SITH_COUNTER_BANK = [ SITH_COUNTER_BANK = [
("OTHER", "Autre"), ("OTHER", "Autre"),
("SOCIETE-GENERALE", "Société générale"), ("SOCIETE-GENERALE", "Société générale"),

View File

@ -21,6 +21,7 @@ from django.utils.timezone import localdate
from django.views.generic import CreateView, DetailView, TemplateView from django.views.generic import CreateView, DetailView, TemplateView
from django.views.generic.edit import FormView from django.views.generic.edit import FormView
from counter.apps import PAYMENT_METHOD
from subscription.forms import ( from subscription.forms import (
SelectionDateForm, SelectionDateForm,
SubscriptionExistingUserForm, SubscriptionExistingUserForm,
@ -108,6 +109,6 @@ class SubscriptionsStatsView(FormView):
subscription_end__gte=self.end_date, subscription_start__lte=self.start_date subscription_end__gte=self.end_date, subscription_start__lte=self.start_date
) )
kwargs["subscriptions_types"] = settings.SITH_SUBSCRIPTIONS kwargs["subscriptions_types"] = settings.SITH_SUBSCRIPTIONS
kwargs["payment_types"] = settings.SITH_COUNTER_PAYMENT_METHOD kwargs["payment_types"] = PAYMENT_METHOD
kwargs["locations"] = settings.SITH_SUBSCRIPTION_LOCATIONS kwargs["locations"] = settings.SITH_SUBSCRIPTION_LOCATIONS
return kwargs return kwargs