mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-11-04 09:12:11 +01:00 
			
		
		
		
	Deposit check logic changed
This commit is contained in:
		@@ -1391,12 +1391,12 @@
 | 
			
		||||
                "wei",
 | 
			
		||||
                "weiregistration"
 | 
			
		||||
            ],
 | 
			
		||||
            "query": "{\"wei\": [\"club\"], \"wei__membership_end__gte\": [\"today\"]}",
 | 
			
		||||
            "query": "[\"AND\", {\"wei\": [\"club\"], \"wei__membership_end__gte\": [\"today\"]}, {\"deposit_type\": \"note\"}]",
 | 
			
		||||
            "type": "change",
 | 
			
		||||
            "mask": 2,
 | 
			
		||||
            "field": "caution_check",
 | 
			
		||||
            "permanent": false,
 | 
			
		||||
            "description": "Dire si un chèque de caution est donné pour une inscription WEI"
 | 
			
		||||
            "description": "Autoriser une transaction de caution WEI"
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
@@ -4366,6 +4366,38 @@
 | 
			
		||||
            "description": "Modifier l'équipe d'une adhésion WEI à son bus"
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        "model": "permission.permission",
 | 
			
		||||
        "pk": 294,
 | 
			
		||||
        "fields": {
 | 
			
		||||
            "model": [
 | 
			
		||||
                "wei",
 | 
			
		||||
                "weiregistration"
 | 
			
		||||
            ],
 | 
			
		||||
            "query": "[\"AND\", {\"wei__year\": [\"today\", \"year\"], \"wei__membership_start__lte\": [\"today\"], \"wei__membership_end__gte\": [\"today\"]}, {\"deposit_type\": \"check\"}]",
 | 
			
		||||
            "type": "change",
 | 
			
		||||
            "mask": 2,
 | 
			
		||||
            "field": "caution_check",
 | 
			
		||||
            "permanent": false,
 | 
			
		||||
            "description": "Dire si un chèque de caution a été donné"
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        "model": "permission.permission",
 | 
			
		||||
        "pk": 295,
 | 
			
		||||
        "fields": {
 | 
			
		||||
            "model": [
 | 
			
		||||
                "wei",
 | 
			
		||||
                "weiregistration"
 | 
			
		||||
            ],
 | 
			
		||||
            "query": "{\"wei__year\": [\"today\", \"year\"]}",
 | 
			
		||||
            "type": "view",
 | 
			
		||||
            "mask": 2,
 | 
			
		||||
            "field": "",
 | 
			
		||||
            "permanent": false,
 | 
			
		||||
            "description": "Voir toutes les inscriptions au WEI courant"
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        "model": "permission.role",
 | 
			
		||||
        "pk": 1,
 | 
			
		||||
@@ -4647,7 +4679,9 @@
 | 
			
		||||
                176,
 | 
			
		||||
                177,
 | 
			
		||||
                178,
 | 
			
		||||
                183
 | 
			
		||||
                183,
 | 
			
		||||
                294,
 | 
			
		||||
                295
 | 
			
		||||
            ]
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
 
 | 
			
		||||
@@ -77,7 +77,7 @@ class WEIRegistrationViewSet(ReadProtectedModelViewSet):
 | 
			
		||||
    filter_backends = [DjangoFilterBackend, RegexSafeSearchFilter]
 | 
			
		||||
    filterset_fields = ['user', 'user__username', 'user__first_name', 'user__last_name', 'user__email',
 | 
			
		||||
                        'user__note__alias__name', 'user__note__alias__normalized_name', 'wei', 'wei__name',
 | 
			
		||||
                        'wei__email', 'wei__year', 'soge_credit', 'deposit_check', 'birth_date', 'gender',
 | 
			
		||||
                        'wei__email', 'wei__year', 'soge_credit', 'deposit_given', 'birth_date', 'gender',
 | 
			
		||||
                        'clothing_cut', 'clothing_size', 'first_year', 'emergency_contact_name',
 | 
			
		||||
                        'emergency_contact_phone', ]
 | 
			
		||||
    search_fields = ['$user__username', '$user__first_name', '$user__last_name', '$user__email',
 | 
			
		||||
 
 | 
			
		||||
@@ -44,7 +44,7 @@ class WEIRegistrationForm(forms.ModelForm):
 | 
			
		||||
        fields = [
 | 
			
		||||
            'user', 'soge_credit', 'birth_date', 'gender', 'clothing_size',
 | 
			
		||||
            'health_issues', 'emergency_contact_name', 'emergency_contact_phone',
 | 
			
		||||
            'first_year', 'information_json', 'deposit_check', 'deposit_type'
 | 
			
		||||
            'first_year', 'information_json', 'deposit_given', 'deposit_type'
 | 
			
		||||
        ]
 | 
			
		||||
        widgets = {
 | 
			
		||||
            "user": Autocomplete(
 | 
			
		||||
@@ -59,7 +59,7 @@ class WEIRegistrationForm(forms.ModelForm):
 | 
			
		||||
                'minDate': '1900-01-01',
 | 
			
		||||
                'maxDate': '2100-01-01'
 | 
			
		||||
            }),
 | 
			
		||||
            "deposit_check": forms.BooleanField(
 | 
			
		||||
            "deposit_given": forms.BooleanField(
 | 
			
		||||
                required=False,
 | 
			
		||||
            ),
 | 
			
		||||
            "deposit_type": forms.RadioSelect(),
 | 
			
		||||
@@ -161,7 +161,7 @@ class WEIMembership1AForm(WEIMembershipForm):
 | 
			
		||||
    """
 | 
			
		||||
    Used to confirm registrations of first year members without choosing a bus now.
 | 
			
		||||
    """
 | 
			
		||||
    deposit_check = None
 | 
			
		||||
    deposit_given = None
 | 
			
		||||
    roles = None
 | 
			
		||||
 | 
			
		||||
    def clean(self):
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,22 @@
 | 
			
		||||
# Generated by Django 5.2.4 on 2025-08-02 17:59
 | 
			
		||||
 | 
			
		||||
from django.db import migrations, models
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Migration(migrations.Migration):
 | 
			
		||||
 | 
			
		||||
    dependencies = [
 | 
			
		||||
        ('wei', '0017_alter_weiclub_fee_soge_credit'),
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    operations = [
 | 
			
		||||
        migrations.RemoveField(
 | 
			
		||||
            model_name='weiregistration',
 | 
			
		||||
            name='deposit_check',
 | 
			
		||||
        ),
 | 
			
		||||
        migrations.AddField(
 | 
			
		||||
            model_name='weiregistration',
 | 
			
		||||
            name='deposit_given',
 | 
			
		||||
            field=models.BooleanField(default=False, verbose_name='Deposit given'),
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
@@ -202,9 +202,9 @@ class WEIRegistration(models.Model):
 | 
			
		||||
        verbose_name=_("Credit from Société générale"),
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    deposit_check = models.BooleanField(
 | 
			
		||||
    deposit_given = models.BooleanField(
 | 
			
		||||
        default=False,
 | 
			
		||||
        verbose_name=_("Deposit check given")
 | 
			
		||||
        verbose_name=_("Deposit given")
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    deposit_type = models.CharField(
 | 
			
		||||
 
 | 
			
		||||
@@ -84,6 +84,35 @@ class WEIRegistrationTable(tables.Table):
 | 
			
		||||
        },
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    def render_deposit_type(self, record):
 | 
			
		||||
        if record.first_year:
 | 
			
		||||
            return format_html("∅")
 | 
			
		||||
        if record.deposit_type == 'check':
 | 
			
		||||
            # TODO Install Font Awesome 6 to acces more icons (and keep compaibility with current used v4)
 | 
			
		||||
            return format_html("""
 | 
			
		||||
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640" width="1.5em" height="1.5em"
 | 
			
		||||
        fill="currentColor" style="position: relative; left: -0.15em;">
 | 
			
		||||
            <path d="
 | 
			
		||||
                M128 128C92.7 128 64 156.7 64 192L64 448C64 483.3 92.7 512 128 512L512 512
 | 
			
		||||
                C547.3 512 576 483.3 576 448L576 192C576 156.7 547.3 128 512 128L128 128z
 | 
			
		||||
                M360 352L488 352C501.3 352 512 362.7 512 376C512 389.3 501.3 400 488 400L360 400
 | 
			
		||||
                C346.7 400 336 389.3 336 376C336 362.7 346.7 352 360 352z
 | 
			
		||||
                M336 264C336 250.7 346.7 240 360 240L488 240C501.3 240 512 250.7 512 264
 | 
			
		||||
                C512 277.3 501.3 288 488 288L360 288C346.7 288 336 277.3 336 264z
 | 
			
		||||
                M212 208C223 208 232 217 232 228L232 232L240 232C251 232 260 241 260 252
 | 
			
		||||
                C260 263 251 272 240 272L192.5 272C185.6 272 180 277.6 180 284.5
 | 
			
		||||
                C180 290.6 184.4 295.8 190.4 296.8L232.1 303.8C257.4 308 276 329.9 276 355.6
 | 
			
		||||
                C276 381.7 257 403.3 232 407.4L232 412.1C232 423.1 223 432.1 212 432.1
 | 
			
		||||
                C201 432.1 192 423.1 192 412.1L192 408.1L168 408.1C157 408.1 148 399.1 148 388.1
 | 
			
		||||
                C148 377.1 157 368.1 168 368.1L223.5 368.1C230.4 368.1 236 362.5 236 355.6
 | 
			
		||||
                C236 349.5 231.6 344.3 225.6 343.3L183.9 336.3C158.5 332 140 310.1 140 284.5
 | 
			
		||||
                C140 255.7 163.2 232.3 192 232L192 228C192 217 201 208 212 208z
 | 
			
		||||
            " />
 | 
			
		||||
        </svg>
 | 
			
		||||
    """)
 | 
			
		||||
        if record.deposit_type == 'note':
 | 
			
		||||
            return format_html("<i class=\"fa fa-exchange\"></i>")
 | 
			
		||||
 | 
			
		||||
    def render_validate(self, record):
 | 
			
		||||
        hasperm = PermissionBackend.check_perm(
 | 
			
		||||
            get_current_request(), "wei.add_weimembership", WEIMembership(
 | 
			
		||||
@@ -125,8 +154,8 @@ class WEIRegistrationTable(tables.Table):
 | 
			
		||||
        order_by = ('validate', 'user',)
 | 
			
		||||
        model = WEIRegistration
 | 
			
		||||
        template_name = 'django_tables2/bootstrap4.html'
 | 
			
		||||
        fields = ('user', 'user__first_name', 'user__last_name', 'first_year', 'deposit_check',
 | 
			
		||||
                  'edit', 'validate', 'delete',)
 | 
			
		||||
        fields = ('user', 'user__first_name', 'user__last_name', 'first_year', 'deposit_given',
 | 
			
		||||
                  'deposit_type', 'edit', 'validate', 'delete',)
 | 
			
		||||
        row_attrs = {
 | 
			
		||||
            'class': 'table-row',
 | 
			
		||||
            'id': lambda record: "row-" + str(record.pk),
 | 
			
		||||
@@ -165,7 +194,7 @@ class WEIMembershipTable(tables.Table):
 | 
			
		||||
        model = WEIMembership
 | 
			
		||||
        template_name = 'django_tables2/bootstrap4.html'
 | 
			
		||||
        fields = ('user', 'user__last_name', 'user__first_name', 'registration__gender', 'user__profile__department',
 | 
			
		||||
                  'year', 'bus', 'team', 'registration__deposit_check', )
 | 
			
		||||
                  'year', 'bus', 'team', 'registration__deposit_given', )
 | 
			
		||||
        row_attrs = {
 | 
			
		||||
            'class': 'table-row',
 | 
			
		||||
            'id': lambda record: "row-" + str(record.pk),
 | 
			
		||||
 
 | 
			
		||||
@@ -96,7 +96,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
 | 
			
		||||
                    {% endif %}
 | 
			
		||||
                {% else %}
 | 
			
		||||
                    <dt class="col-xl-6">{% trans 'Deposit check given'|capfirst %}</dt>
 | 
			
		||||
                    <dd class="col-xl-6">{{ registration.deposit_check|yesno }}</dd>
 | 
			
		||||
                    <dd class="col-xl-6">{{ registration.deposit_given|yesno }}</dd>
 | 
			
		||||
 | 
			
		||||
                    {% with information=registration.information %}
 | 
			
		||||
                        <dt class="col-xl-6">{% trans 'preferred bus'|capfirst %}</dt>
 | 
			
		||||
@@ -169,9 +169,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
 | 
			
		||||
                    {% endblocktrans %}</p>
 | 
			
		||||
                    </div>
 | 
			
		||||
 | 
			
		||||
                {% if not registration.deposit_check and not registration.first_year and registration.caution_type == 'check' %}
 | 
			
		||||
                {% if not registration.deposit_given and not registration.first_year and registration.caution_type == 'check' %}
 | 
			
		||||
                    <div class="alert alert-danger">
 | 
			
		||||
                        {% trans "The user didn't give her/his caution check." %}
 | 
			
		||||
                        {% trans "The user didn't give her/his caution." %}
 | 
			
		||||
                    </div>
 | 
			
		||||
                {% endif %}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -126,7 +126,8 @@ class TestWEIAlgorithm(TestCase):
 | 
			
		||||
            for r2 in WEIRegistration.objects.filter(wei=self.wei, pk__gt=r1.pk):
 | 
			
		||||
                survey2 = WEISurvey2025(r2)
 | 
			
		||||
                bus2 = survey2.information.get_selected_bus()
 | 
			
		||||
                
 | 
			
		||||
 | 
			
		||||
                prefer_switch_bus_words = survey1.score_words(bus2) > survey1.score_words(bus1) and survey2.score_words(bus1) > survey2.score_words(bus2)
 | 
			
		||||
                prefer_switch_bus_questions = survey1.score_questions(bus2) > survey1.score_questions(bus1) and survey2.score_questions(bus1) > survey2.score_questions(bus2)
 | 
			
		||||
                self.assertFalse(prefer_switch_bus_words and prefer_switch_bus_questions)
 | 
			
		||||
                prefer_switch_bus_questions = survey1.score_questions(bus2) > survey1.score_questions(bus1) and\
 | 
			
		||||
                    survey2.score_questions(bus1) > survey2.score_questions(bus2)
 | 
			
		||||
                self.assertFalse(prefer_switch_bus_words and prefer_switch_bus_questions)
 | 
			
		||||
 
 | 
			
		||||
@@ -101,7 +101,7 @@ class TestWEIRegistration(TestCase):
 | 
			
		||||
            user_id=self.user.id,
 | 
			
		||||
            wei_id=self.wei.id,
 | 
			
		||||
            soge_credit=True,
 | 
			
		||||
            deposit_check=True,
 | 
			
		||||
            deposit_given=True,
 | 
			
		||||
            birth_date=date(2000, 1, 1),
 | 
			
		||||
            gender="nonbinary",
 | 
			
		||||
            clothing_cut="male",
 | 
			
		||||
@@ -642,7 +642,7 @@ class TestWEIRegistration(TestCase):
 | 
			
		||||
            last_name="admin",
 | 
			
		||||
            first_name="admin",
 | 
			
		||||
            bank="Société générale",
 | 
			
		||||
            deposit_check=True,
 | 
			
		||||
            deposit_given=True,
 | 
			
		||||
        ))
 | 
			
		||||
        self.assertEqual(response.status_code, 200)
 | 
			
		||||
        self.assertFalse(response.context["form"].is_valid())
 | 
			
		||||
@@ -657,7 +657,7 @@ class TestWEIRegistration(TestCase):
 | 
			
		||||
            last_name="admin",
 | 
			
		||||
            first_name="admin",
 | 
			
		||||
            bank="Société générale",
 | 
			
		||||
            deposit_check=True,
 | 
			
		||||
            deposit_given=True,
 | 
			
		||||
        ))
 | 
			
		||||
        self.assertRedirects(response, reverse("wei:wei_registrations", kwargs=dict(pk=self.registration.wei.pk)), 302, 200)
 | 
			
		||||
 | 
			
		||||
@@ -813,7 +813,7 @@ class TestWeiAPI(TestAPI):
 | 
			
		||||
            user_id=self.user.id,
 | 
			
		||||
            wei_id=self.wei.id,
 | 
			
		||||
            soge_credit=True,
 | 
			
		||||
            deposit_check=True,
 | 
			
		||||
            deposit_given=True,
 | 
			
		||||
            birth_date=date(2000, 1, 1),
 | 
			
		||||
            gender="nonbinary",
 | 
			
		||||
            clothing_cut="male",
 | 
			
		||||
 
 | 
			
		||||
@@ -594,8 +594,8 @@ class WEIRegister1AView(ProtectQuerysetMixin, ProtectedCreateView):
 | 
			
		||||
        # Cacher les champs pendant l'inscription initiale
 | 
			
		||||
        if "first_year" in form.fields:
 | 
			
		||||
            del form.fields["first_year"]
 | 
			
		||||
        if "deposit_check" in form.fields:
 | 
			
		||||
            del form.fields["deposit_check"]
 | 
			
		||||
        if "deposit_given" in form.fields:
 | 
			
		||||
            del form.fields["deposit_given"]
 | 
			
		||||
        if "information_json" in form.fields:
 | 
			
		||||
            del form.fields["information_json"]
 | 
			
		||||
        if "deposit_type" in form.fields:
 | 
			
		||||
@@ -704,8 +704,8 @@ class WEIRegister2AView(ProtectQuerysetMixin, ProtectedCreateView):
 | 
			
		||||
        # Cacher les champs pendant l'inscription initiale
 | 
			
		||||
        if "first_year" in form.fields:
 | 
			
		||||
            del form.fields["first_year"]
 | 
			
		||||
        if "deposit_check" in form.fields:
 | 
			
		||||
            del form.fields["deposit_check"]
 | 
			
		||||
        if "deposit_given" in form.fields:
 | 
			
		||||
            del form.fields["deposit_given"]
 | 
			
		||||
        if "information_json" in form.fields:
 | 
			
		||||
            del form.fields["information_json"]
 | 
			
		||||
 | 
			
		||||
@@ -806,9 +806,9 @@ class WEIUpdateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Update
 | 
			
		||||
        # The auto-json-format may cause issues with the default field remove
 | 
			
		||||
        if "information_json" in form.fields:
 | 
			
		||||
            del form.fields["information_json"]
 | 
			
		||||
        # Masquer le champ deposit_check pour tout le monde dans le formulaire de modification
 | 
			
		||||
        if "deposit_check" in form.fields:
 | 
			
		||||
            del form.fields["deposit_check"]
 | 
			
		||||
        # Masquer le champ deposit_given pour tout le monde dans le formulaire de modification
 | 
			
		||||
        if "deposit_given" in form.fields:
 | 
			
		||||
            del form.fields["deposit_given"]
 | 
			
		||||
 | 
			
		||||
        # S'assurer que le champ deposit_type est obligatoire pour les 2A+
 | 
			
		||||
        if "deposit_type" in form.fields:
 | 
			
		||||
@@ -818,6 +818,14 @@ class WEIUpdateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Update
 | 
			
		||||
                form.fields["deposit_type"].required = True
 | 
			
		||||
                form.fields["deposit_type"].help_text = _("Choose how you want to pay the deposit")
 | 
			
		||||
 | 
			
		||||
        if not self.object.first_year and self.object.deposit_type == 'check':
 | 
			
		||||
            form.fields["deposit_given"] = forms.BooleanField(
 | 
			
		||||
                required=False,
 | 
			
		||||
                initial=self.object.deposit_given,
 | 
			
		||||
                label=_("Deposit check given"),
 | 
			
		||||
                help_text=_("Tick if the deposit check has been given")
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        if self.object.user.profile.soge:
 | 
			
		||||
            form.fields["soge_credit"].disabled = True
 | 
			
		||||
            form.fields["soge_credit"].help_text = _("You already opened an account in the Société générale.")
 | 
			
		||||
@@ -1016,17 +1024,18 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
 | 
			
		||||
        form.fields["last_name"].initial = registration.user.last_name
 | 
			
		||||
        form.fields["first_name"].initial = registration.user.first_name
 | 
			
		||||
 | 
			
		||||
        # Ajouter le champ deposit_check uniquement pour les non-première année et le rendre obligatoire
 | 
			
		||||
        # Ajouter le champ deposit_given uniquement pour les non-première année et le rendre obligatoire
 | 
			
		||||
        if not registration.first_year:
 | 
			
		||||
            if registration.deposit_type == 'check':
 | 
			
		||||
                form.fields["deposit_check"] = forms.BooleanField(
 | 
			
		||||
                form.fields["deposit_given"] = forms.BooleanField(
 | 
			
		||||
                    required=True,
 | 
			
		||||
                    initial=registration.deposit_check,
 | 
			
		||||
                    disabled=True,
 | 
			
		||||
                    initial=registration.deposit_given,
 | 
			
		||||
                    label=_("Deposit check given"),
 | 
			
		||||
                    help_text=_("Please make sure the check is given before validating the registration")
 | 
			
		||||
                    help_text=_("Only treasurers can validate this field")
 | 
			
		||||
                )
 | 
			
		||||
            else:
 | 
			
		||||
                form.fields["deposit_check"] = forms.BooleanField(
 | 
			
		||||
                form.fields["deposit_given"] = forms.BooleanField(
 | 
			
		||||
                    required=True,
 | 
			
		||||
                    initial=False,
 | 
			
		||||
                    label=_("Create deposit transaction"),
 | 
			
		||||
@@ -1067,8 +1076,8 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
 | 
			
		||||
        club = registration.wei
 | 
			
		||||
        user = registration.user
 | 
			
		||||
 | 
			
		||||
        if "deposit_check" in form.data:
 | 
			
		||||
            registration.deposit_check = form.data["deposit_check"] == "on"
 | 
			
		||||
        if "deposit_given" in form.data:
 | 
			
		||||
            registration.deposit_given = form.data["deposit_given"] == "on"
 | 
			
		||||
            registration.save()
 | 
			
		||||
        membership = form.instance
 | 
			
		||||
        membership.user = user
 | 
			
		||||
@@ -1180,7 +1189,7 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
 | 
			
		||||
    def form_invalid(self, form):
 | 
			
		||||
        registration = getattr(form.instance, "registration", None)
 | 
			
		||||
        if registration is not None:
 | 
			
		||||
            registration.deposit_check = False
 | 
			
		||||
            registration.deposit_given = False
 | 
			
		||||
            registration.save()
 | 
			
		||||
        return super().form_invalid(form)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user