From 3af35dc0fc4617be26eb006560174204097c3291 Mon Sep 17 00:00:00 2001 From: Ehouarn Date: Tue, 15 Jul 2025 17:43:21 +0200 Subject: [PATCH] Soge Credit changed --- apps/member/models.py | 6 --- apps/treasury/models.py | 4 +- .../0014_weiclub_fee_soge_credit.py | 18 +++++++ apps/wei/models.py | 8 ++- .../wei/templates/wei/weimembership_form.html | 52 +++++++++---------- apps/wei/tests/test_wei_registration.py | 6 +-- apps/wei/views.py | 19 +++---- 7 files changed, 59 insertions(+), 54 deletions(-) create mode 100644 apps/wei/migrations/0014_weiclub_fee_soge_credit.py diff --git a/apps/member/models.py b/apps/member/models.py index 54637847..ea859ea5 100644 --- a/apps/member/models.py +++ b/apps/member/models.py @@ -438,8 +438,6 @@ class Membership(models.Model): ) if hasattr(self, '_force_renew_parent') and self._force_renew_parent: new_membership._force_renew_parent = True - if hasattr(self, '_soge') and self._soge: - new_membership._soge = True if hasattr(self, '_force_save') and self._force_save: new_membership._force_save = True new_membership.save() @@ -458,8 +456,6 @@ class Membership(models.Model): # Renew the previous membership of the parent club parent_membership = parent_membership.first() parent_membership._force_renew_parent = True - if hasattr(self, '_soge'): - parent_membership._soge = True if hasattr(self, '_force_save'): parent_membership._force_save = True parent_membership.renew() @@ -471,8 +467,6 @@ class Membership(models.Model): date_start=self.date_start, ) parent_membership._force_renew_parent = True - if hasattr(self, '_soge'): - parent_membership._soge = True if hasattr(self, '_force_save'): parent_membership._force_save = True parent_membership.save() diff --git a/apps/treasury/models.py b/apps/treasury/models.py index 7695ac02..214203a9 100644 --- a/apps/treasury/models.py +++ b/apps/treasury/models.py @@ -353,7 +353,7 @@ class SogeCredit(models.Model): def amount(self): if self.valid: return self.credit_transaction.total - amount = sum(transaction.total for transaction in self.transactions.all()) + amount = sum(max(transaction.total - 2000, 0) for transaction in self.transactions.all()) if 'wei' in settings.INSTALLED_APPS: from wei.models import WEIMembership if not WEIMembership.objects\ @@ -441,7 +441,7 @@ class SogeCredit(models.Model): With Great Power Comes Great Responsibility... """ - total_fee = sum(transaction.total for transaction in self.transactions.all() if not transaction.valid) + total_fee = sum(max(transaction.total - 2000, 0) for transaction in self.transactions.all() if not transaction.valid) if self.user.note.balance < total_fee: raise ValidationError(_("This user doesn't have enough money to pay the memberships with its note. " "Please ask her/him to credit the note before invalidating this credit.")) diff --git a/apps/wei/migrations/0014_weiclub_fee_soge_credit.py b/apps/wei/migrations/0014_weiclub_fee_soge_credit.py new file mode 100644 index 00000000..c353ec0f --- /dev/null +++ b/apps/wei/migrations/0014_weiclub_fee_soge_credit.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.23 on 2025-07-15 14:05 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wei', '0013_weiclub_caution_amount_weiregistration_caution_type'), + ] + + operations = [ + migrations.AddField( + model_name='weiclub', + name='fee_soge_credit', + field=models.PositiveIntegerField(default=2000, verbose_name='fee soge credit'), + ), + ] diff --git a/apps/wei/models.py b/apps/wei/models.py index 684feaf8..cf31997f 100644 --- a/apps/wei/models.py +++ b/apps/wei/models.py @@ -38,6 +38,11 @@ class WEIClub(Club): default=0, ) + fee_soge_credit = models.PositiveIntegerField( + verbose_name=_("fee soge credit"), + default=2000, + ) + class Meta: verbose_name = _("WEI") verbose_name_plural = _("WEI") @@ -319,7 +324,8 @@ class WEIRegistration(models.Model): date_start__gte=bde.membership_start, ).exists() - fee = self.wei.membership_fee_paid if self.user.profile.paid \ + fee = self.wei.fee_soge_credit if self.soge_credit \ + else self.wei.membership_fee_paid if self.user.profile.paid \ else self.wei.membership_fee_unpaid if not kfet_member: fee += kfet.membership_fee_paid if self.user.profile.paid \ diff --git a/apps/wei/templates/wei/weimembership_form.html b/apps/wei/templates/wei/weimembership_form.html index a9c85d5d..483e1297 100644 --- a/apps/wei/templates/wei/weimembership_form.html +++ b/apps/wei/templates/wei/weimembership_form.html @@ -137,39 +137,35 @@ SPDX-License-Identifier: GPL-3.0-or-later {% if registration.soge_credit %}
{% blocktrans trimmed %} - The WEI will be paid by Société générale. The membership will be created even if the bank didn't pay the BDE yet. + The WEI will partially be paid by Société générale. The membership will be created even if the bank didn't pay the BDE yet. The membership transaction will be created but will be invalid. You will have to validate it once the bank validated the creation of the account, or to change the payment method. {% endblocktrans %}
- {% else %} -
-
{% trans "Required payments:" %}
- -

{% blocktrans trimmed with balance=registration.user.note.balance|pretty_money %} - Current balance: {{ balance }} - {% endblocktrans %}

-
{% endif %} +
+
{% trans "Required payments:" %}
+ +

{% blocktrans trimmed with balance=registration.user.note.balance|pretty_money %} + Current balance: {{ balance }} + {% endblocktrans %}

+
{% if not registration.caution_check and not registration.first_year and registration.caution_type == 'check' %}
diff --git a/apps/wei/tests/test_wei_registration.py b/apps/wei/tests/test_wei_registration.py index d286581c..62e73235 100644 --- a/apps/wei/tests/test_wei_registration.py +++ b/apps/wei/tests/test_wei_registration.py @@ -121,6 +121,7 @@ class TestWEIRegistration(TestCase): email="gc.wei@example.com", membership_fee_paid=12500, membership_fee_unpaid=5500, + fee_soge_credit=2000, membership_start=str(self.year + 1) + "-08-01", membership_end=str(self.year + 1) + "-09-30", year=self.year + 1, @@ -157,6 +158,7 @@ class TestWEIRegistration(TestCase): email="wei-updated@example.com", membership_fee_paid=0, membership_fee_unpaid=0, + fee_soge_credit=0, membership_start="2000-08-01", membership_end="2000-09-30", date_start="2000-09-01", @@ -678,11 +680,7 @@ class TestWEIRegistration(TestCase): self.assertTrue(soge_credit.exists()) soge_credit = soge_credit.get() self.assertTrue(membership.transaction in soge_credit.transactions.all()) - self.assertTrue(kfet_membership.transaction in soge_credit.transactions.all()) - self.assertTrue(bde_membership.transaction in soge_credit.transactions.all()) self.assertFalse(membership.transaction.valid) - self.assertFalse(kfet_membership.transaction.valid) - self.assertFalse(bde_membership.transaction.valid) # Check that if the WEI is started, we can't update a wei self.wei.date_start = date(2000, 1, 1) diff --git a/apps/wei/views.py b/apps/wei/views.py index dc9782d7..dbfd1774 100644 --- a/apps/wei/views.py +++ b/apps/wei/views.py @@ -27,7 +27,7 @@ from django.views.generic.edit import BaseFormView, DeleteView from django_tables2 import SingleTableView, MultiTableMixin from api.viewsets import is_regex from member.models import Membership, Club -from note.models import Transaction, NoteClub, Alias, SpecialTransaction, NoteSpecial +from note.models import Transaction, NoteClub, Alias, SpecialTransaction from note.tables import HistoryTable from note_kfet.settings import BASE_DIR from permission.backends import PermissionBackend @@ -662,7 +662,7 @@ class WEIRegister2AView(ProtectQuerysetMixin, ProtectedCreateView): form.fields["user"].initial = self.request.user if "soge_credit" in form.fields: form.fields["soge_credit"].help_text = _('Check if you will open a Société Générale account') - + if "myself" in self.request.path and self.request.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.") @@ -1007,15 +1007,6 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView): } ) - if registration.soge_credit: - form.fields["credit_type"].disabled = True - form.fields["credit_type"].initial = NoteSpecial.objects.get(special_type="Virement bancaire") - form.fields["credit_amount"].disabled = True - form.fields["last_name"].disabled = True - form.fields["first_name"].disabled = True - form.fields["bank"].disabled = True - form.fields["bank"].initial = "Société générale" - if 'bus' in form.fields: # For 2A+ and hardcoded 1A form.fields["bus"].widget.attrs["api_url"] = "/api/wei/bus/?wei=" + str(registration.wei.pk) @@ -1060,6 +1051,8 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView): membership._force_renew_parent = True fee = club.membership_fee_paid if user.profile.paid else club.membership_fee_unpaid + if registration.soge_credit: + fee = 2000 kfet = club.parent_club bde = kfet.parent_club @@ -1086,7 +1079,7 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView): first_name = form.cleaned_data["first_name"] bank = form.cleaned_data["bank"] - if credit_type is None or registration.soge_credit: + if credit_type is None: credit_amount = 0 # Calculer le montant total nécessaire (frais + caution si transaction) @@ -1095,7 +1088,7 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView): total_needed += club.caution_amount # Vérifier que l'utilisateur a assez d'argent pour tout payer - if not registration.soge_credit and user.note.balance + credit_amount < total_needed: + if user.note.balance + credit_amount < total_needed: form.add_error('credit_type', _("This user doesn't have enough money to join this club and pay the deposit. " "Current balance: %(balance)d€, credit: %(credit)d€, needed: %(needed)d€") % {