mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-07-17 14:55:53 +02:00
Soge Credit changed
This commit is contained in:
@ -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()
|
||||
|
@ -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."))
|
||||
|
18
apps/wei/migrations/0014_weiclub_fee_soge_credit.py
Normal file
18
apps/wei/migrations/0014_weiclub_fee_soge_credit.py
Normal file
@ -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'),
|
||||
),
|
||||
]
|
@ -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 \
|
||||
|
@ -137,39 +137,35 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
{% if registration.soge_credit %}
|
||||
<div class="alert alert-warning">
|
||||
{% 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 %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="alert {% if registration.user.note.balance < fee %}alert-danger{% else %}alert-success{% endif %}">
|
||||
<h5>{% trans "Required payments:" %}</h5>
|
||||
<ul>
|
||||
<li>{% blocktrans trimmed with amount=fee|pretty_money %}
|
||||
Membership fees: {{ amount }}
|
||||
{% endblocktrans %}</li>
|
||||
{% if registration.caution_type == 'note' %}
|
||||
<li>{% blocktrans trimmed with amount=club.caution_amount|pretty_money %}
|
||||
Deposit (by Note transaction): {{ amount }}
|
||||
{% endblocktrans %}</li>
|
||||
<li><strong>{% blocktrans trimmed with total=total_needed|pretty_money %}
|
||||
Total needed: {{ total }}
|
||||
{% endblocktrans %}</strong></li>
|
||||
{% else %}
|
||||
<li>{% blocktrans trimmed with amount=club.caution_amount|pretty_money %}
|
||||
Deposit (by check): {{ amount }}
|
||||
{% endblocktrans %}</li>
|
||||
<li><strong>{% blocktrans trimmed with total=fee|pretty_money %}
|
||||
Total needed: {{ total }}
|
||||
{% endblocktrans %}</strong></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
<p>{% blocktrans trimmed with balance=registration.user.note.balance|pretty_money %}
|
||||
Current balance: {{ balance }}
|
||||
{% endblocktrans %}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="alert {% if registration.user.note.balance < fee %}alert-danger{% else %}alert-success{% endif %}">
|
||||
<h5>{% trans "Required payments:" %}</h5>
|
||||
<ul>
|
||||
<li>{% blocktrans trimmed with amount=fee|pretty_money %}
|
||||
Membership fees: {{ amount }}
|
||||
{% endblocktrans %}</li>
|
||||
{% if registration.caution_type == 'note' %}
|
||||
<li>{% blocktrans trimmed with amount=club.caution_amount|pretty_money %}
|
||||
Deposit (by Note transaction): {{ amount }}
|
||||
{% endblocktrans %}</li>
|
||||
{% else %}
|
||||
<li>{% blocktrans trimmed with amount=club.caution_amount|pretty_money %}
|
||||
Deposit (by check): {{ amount }}
|
||||
{% endblocktrans %}</li>
|
||||
{% endif %}
|
||||
<li><strong>{% blocktrans trimmed with total=total_needed|pretty_money %}
|
||||
Total needed: {{ total }}
|
||||
{% endblocktrans %}</strong></li>
|
||||
</ul>
|
||||
<p>{% blocktrans trimmed with balance=registration.user.note.balance|pretty_money %}
|
||||
Current balance: {{ balance }}
|
||||
{% endblocktrans %}</p>
|
||||
</div>
|
||||
|
||||
{% if not registration.caution_check and not registration.first_year and registration.caution_type == 'check' %}
|
||||
<div class="alert alert-danger">
|
||||
|
@ -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)
|
||||
|
@ -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€") % {
|
||||
|
Reference in New Issue
Block a user