diff --git a/counter/apps.py b/counter/apps.py index 54e7ad4c..9348cd1c 100644 --- a/counter/apps.py +++ b/counter/apps.py @@ -24,6 +24,12 @@ from django.apps import AppConfig from django.utils.translation import gettext_lazy as _ +PAYMENT_METHOD = [ + ("CHECK", _("Check")), + ("CASH", _("Cash")), + ("CARD", _("Credit card")), +] + class CounterConfig(AppConfig): name = "counter" diff --git a/counter/forms.py b/counter/forms.py index 0a8bb3be..80a0e0ad 100644 --- a/counter/forms.py +++ b/counter/forms.py @@ -111,6 +111,8 @@ class GetUserForm(forms.Form): class RefillForm(forms.ModelForm): + allowed_refilling_methods = ["CASH", "CARD"] + error_css_class = "error" required_css_class = "required" amount = forms.FloatField( @@ -120,6 +122,21 @@ class RefillForm(forms.ModelForm): class Meta: model = Refilling 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): diff --git a/counter/migrations/0027_alter_refilling_payment_method.py b/counter/migrations/0027_alter_refilling_payment_method.py new file mode 100644 index 00000000..af9dd54a --- /dev/null +++ b/counter/migrations/0027_alter_refilling_payment_method.py @@ -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", + ), + ), + ] diff --git a/counter/models.py b/counter/models.py index da2f33f4..3640c3f5 100644 --- a/counter/models.py +++ b/counter/models.py @@ -42,6 +42,7 @@ from club.models import Club from core.fields import ResizedImageField from core.models import Group, Notification, User 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 subscription.models import Subscription @@ -697,8 +698,8 @@ class Refilling(models.Model): payment_method = models.CharField( _("payment method"), max_length=255, - choices=settings.SITH_COUNTER_PAYMENT_METHOD, - default="CASH", + choices=PAYMENT_METHOD, + default="CARD", ) bank = models.CharField( _("bank"), max_length=255, choices=settings.SITH_COUNTER_BANK, default="OTHER" diff --git a/counter/templates/counter/counter_click.jinja b/counter/templates/counter/counter_click.jinja index 65c7d9ca..bc5c4e58 100644 --- a/counter/templates/counter/counter_click.jinja +++ b/counter/templates/counter/counter_click.jinja @@ -29,11 +29,6 @@ {{ user_mini_profile(customer.user) }} {{ user_subscription(customer.user) }}
{% trans %}Amount: {% endtrans %} €
- - {% if counter.type == 'BAR' %} -