mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 07:41:14 +00:00
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:
parent
cde864fdc7
commit
f63fb59cbf
@ -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"
|
||||
|
@ -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):
|
||||
|
22
counter/migrations/0027_alter_refilling_payment_method.py
Normal file
22
counter/migrations/0027_alter_refilling_payment_method.py
Normal 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",
|
||||
),
|
||||
),
|
||||
]
|
@ -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"
|
||||
|
@ -29,11 +29,6 @@
|
||||
{{ user_mini_profile(customer.user) }}
|
||||
{{ user_subscription(customer.user) }}
|
||||
<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 id="click_form">
|
||||
@ -113,6 +108,12 @@
|
||||
{{ refilling_fragment }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if student_card_fragment %}
|
||||
<h5>{% trans %}Student card{% endtrans %}</h3>
|
||||
<div>
|
||||
{{ student_card_fragment }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div id="products">
|
||||
|
@ -394,9 +394,11 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView):
|
||||
)
|
||||
kwargs["customer"] = self.customer
|
||||
kwargs["basket_total"] = self.sum_basket(self.request)
|
||||
kwargs["student_card_fragment"] = StudentCardFormView.get_template_data(
|
||||
self.customer
|
||||
).render(self.request)
|
||||
|
||||
if self.object.type == "BAR":
|
||||
kwargs["student_card_fragment"] = StudentCardFormView.get_template_data(
|
||||
self.customer
|
||||
).render(self.request)
|
||||
|
||||
if self.object.can_refill():
|
||||
kwargs["refilling_fragment"] = RefillingCreateView.get_template_data(
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -434,12 +434,6 @@ SITH_COUNTER_BARS = [(1, "MDE"), (2, "Foyer"), (35, "La Gommette")]
|
||||
|
||||
SITH_COUNTER_OFFICES = {2: "PdF", 1: "AE"}
|
||||
|
||||
SITH_COUNTER_PAYMENT_METHOD = [
|
||||
("CHECK", _("Check")),
|
||||
("CASH", _("Cash")),
|
||||
("CARD", _("Credit card")),
|
||||
]
|
||||
|
||||
SITH_COUNTER_BANK = [
|
||||
("OTHER", "Autre"),
|
||||
("SOCIETE-GENERALE", "Société générale"),
|
||||
|
@ -21,6 +21,7 @@ from django.utils.timezone import localdate
|
||||
from django.views.generic import CreateView, DetailView, TemplateView
|
||||
from django.views.generic.edit import FormView
|
||||
|
||||
from counter.apps import PAYMENT_METHOD
|
||||
from subscription.forms import (
|
||||
SelectionDateForm,
|
||||
SubscriptionExistingUserForm,
|
||||
@ -108,6 +109,6 @@ class SubscriptionsStatsView(FormView):
|
||||
subscription_end__gte=self.end_date, subscription_start__lte=self.start_date
|
||||
)
|
||||
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
|
||||
return kwargs
|
||||
|
Loading…
Reference in New Issue
Block a user