mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-08-11 00:15:21 +02:00
Compare commits
2 Commits
023fc1db84
...
573f2d8a22
Author | SHA1 | Date | |
---|---|---|---|
|
573f2d8a22 | ||
|
8e98d62b69 |
18
apps/member/migrations/0015_alter_profile_promotion.py
Normal file
18
apps/member/migrations/0015_alter_profile_promotion.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.2.4 on 2025-08-02 13:43
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('member', '0014_create_bda'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='profile',
|
||||||
|
name='promotion',
|
||||||
|
field=models.PositiveSmallIntegerField(default=2025, help_text='Year of entry to the school (None if not ENS student)', null=True, verbose_name='promotion'),
|
||||||
|
),
|
||||||
|
]
|
@@ -353,13 +353,11 @@ class SogeCredit(models.Model):
|
|||||||
def amount(self):
|
def amount(self):
|
||||||
if self.valid:
|
if self.valid:
|
||||||
return self.credit_transaction.total
|
return self.credit_transaction.total
|
||||||
amount = sum(max(transaction.total - 2000, 0) for transaction in self.transactions.all())
|
amount = 0
|
||||||
if 'wei' in settings.INSTALLED_APPS:
|
transactions_wei = self.transactions.filter(membership__club__weiclub__isnull=False)
|
||||||
from wei.models import WEIMembership
|
amount += sum(max(transaction.total - transaction.membership.club.weiclub.fee_soge_credit, 0) for transaction in transactions_wei)
|
||||||
if not WEIMembership.objects\
|
transactions_not_wei = self.transactions.filter(membership__club__weiclub__isnull=True)
|
||||||
.filter(club__weiclub__year=self.credit_transaction.created_at.year, user=self.user).exists():
|
amount += sum(transaction.total for transaction in transactions_not_wei)
|
||||||
# 80 € for people that don't go to WEI
|
|
||||||
amount += 8000
|
|
||||||
return amount
|
return amount
|
||||||
|
|
||||||
def update_transactions(self):
|
def update_transactions(self):
|
||||||
@@ -441,7 +439,7 @@ class SogeCredit(models.Model):
|
|||||||
With Great Power Comes Great Responsibility...
|
With Great Power Comes Great Responsibility...
|
||||||
"""
|
"""
|
||||||
|
|
||||||
total_fee = sum(max(transaction.total - 2000, 0) for transaction in self.transactions.all() if not transaction.valid)
|
total_fee = self.amount
|
||||||
if self.user.note.balance < total_fee:
|
if self.user.note.balance < total_fee:
|
||||||
raise ValidationError(_("This user doesn't have enough money to pay the memberships with its note. "
|
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."))
|
"Please ask her/him to credit the note before invalidating this credit."))
|
||||||
|
@@ -365,7 +365,7 @@ class WEISurvey2025(WEISurvey):
|
|||||||
return sum([cls.get_algorithm_class().get_bus_information(bus).scores[word] for bus in buses]) / buses.count()
|
return sum([cls.get_algorithm_class().get_bus_information(bus).scores[word] for bus in buses]) / buses.count()
|
||||||
|
|
||||||
@lru_cache()
|
@lru_cache()
|
||||||
def score(self, bus):
|
def score_questions(self, bus):
|
||||||
"""
|
"""
|
||||||
The score given by the answers to the questions
|
The score given by the answers to the questions
|
||||||
"""
|
"""
|
||||||
@@ -391,7 +391,7 @@ class WEISurvey2025(WEISurvey):
|
|||||||
|
|
||||||
@lru_cache()
|
@lru_cache()
|
||||||
def scores_per_bus(self):
|
def scores_per_bus(self):
|
||||||
return {bus: (self.score(bus), self.score_words(bus)) for bus in self.get_algorithm_class().get_buses()}
|
return {bus: (self.score_questions(bus), self.score_words(bus)) for bus in self.get_algorithm_class().get_buses()}
|
||||||
|
|
||||||
@lru_cache()
|
@lru_cache()
|
||||||
def ordered_buses(self):
|
def ordered_buses(self):
|
||||||
@@ -400,7 +400,6 @@ class WEISurvey2025(WEISurvey):
|
|||||||
"""
|
"""
|
||||||
values = list(self.scores_per_bus().items())
|
values = list(self.scores_per_bus().items())
|
||||||
values.sort(key=lambda item: -item[1][1])
|
values.sort(key=lambda item: -item[1][1])
|
||||||
values = values[:3]
|
|
||||||
return values
|
return values
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -509,17 +508,17 @@ class WEISurveyAlgorithm2025(WEISurveyAlgorithm):
|
|||||||
else:
|
else:
|
||||||
# Current bus has not enough places. Remove the least preferred student from the bus if existing
|
# Current bus has not enough places. Remove the least preferred student from the bus if existing
|
||||||
least_preferred_survey = None
|
least_preferred_survey = None
|
||||||
least_scores = (-1, -1)
|
least_score = -1
|
||||||
# Find the least student in the bus that has a lower score than the current student
|
# Find the least student in the bus that has a lower score than the current student
|
||||||
for survey2 in surveys:
|
for survey2 in surveys:
|
||||||
if not survey2.information.valid or survey2.information.get_selected_bus() != bus:
|
if not survey2.information.valid or survey2.information.get_selected_bus() != bus:
|
||||||
continue
|
continue
|
||||||
scores2 = survey2.score(bus), survey2.score_words(bus)
|
score2 = survey2.score_questions(bus)
|
||||||
if current_scores <= scores2: # Ignore better students
|
if current_scores[0] <= score2: # Ignore better students
|
||||||
continue
|
continue
|
||||||
if least_preferred_survey is None or scores2 < least_scores:
|
if least_preferred_survey is None or score2 < least_score:
|
||||||
least_preferred_survey = survey2
|
least_preferred_survey = survey2
|
||||||
least_scores = scores2
|
least_score = score2
|
||||||
|
|
||||||
if least_preferred_survey is not None:
|
if least_preferred_survey is not None:
|
||||||
# Remove the least student from the bus and put the current student in.
|
# Remove the least student from the bus and put the current student in.
|
||||||
|
18
apps/wei/migrations/0017_alter_weiclub_fee_soge_credit.py
Normal file
18
apps/wei/migrations/0017_alter_weiclub_fee_soge_credit.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.2.4 on 2025-08-02 13:43
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('wei', '0016_weiregistration_fee_alter_weiclub_fee_soge_credit'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='weiclub',
|
||||||
|
name='fee_soge_credit',
|
||||||
|
field=models.PositiveIntegerField(default=0, verbose_name='membership fee (soge credit)'),
|
||||||
|
),
|
||||||
|
]
|
@@ -40,7 +40,7 @@ class WEIClub(Club):
|
|||||||
|
|
||||||
fee_soge_credit = models.PositiveIntegerField(
|
fee_soge_credit = models.PositiveIntegerField(
|
||||||
verbose_name=_("membership fee (soge credit)"),
|
verbose_name=_("membership fee (soge credit)"),
|
||||||
default=2000,
|
default=0,
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@@ -110,6 +110,6 @@ class TestWEIAlgorithm(TestCase):
|
|||||||
max_score = buses[0][1][0]
|
max_score = buses[0][1][0]
|
||||||
penalty += (max_score - score) ** 2
|
penalty += (max_score - score) ** 2
|
||||||
|
|
||||||
self.assertLessEqual(max_score - score, 1) # Always less than 25 % of tolerance
|
self.assertLessEqual(max_score - score, 1)
|
||||||
|
|
||||||
self.assertLessEqual(penalty / 100, 25) # Tolerance of 5 %
|
self.assertLessEqual(penalty / 100, 25) # Tolerance of 5 %
|
||||||
|
@@ -798,11 +798,6 @@ class WEIUpdateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Update
|
|||||||
choose_bus_form.fields["team"].queryset = BusTeam.objects.filter(bus__wei=context["club"])
|
choose_bus_form.fields["team"].queryset = BusTeam.objects.filter(bus__wei=context["club"])
|
||||||
context["membership_form"] = choose_bus_form
|
context["membership_form"] = choose_bus_form
|
||||||
|
|
||||||
if not self.object.soge_credit and self.object.user.profile.soge:
|
|
||||||
form = context["form"]
|
|
||||||
form.fields["soge_credit"].disabled = True
|
|
||||||
form.fields["soge_credit"].help_text = _("You already opened an account in the Société générale.")
|
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_form(self, form_class=None):
|
def get_form(self, form_class=None):
|
||||||
@@ -823,6 +818,10 @@ class WEIUpdateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Update
|
|||||||
form.fields["deposit_type"].required = True
|
form.fields["deposit_type"].required = True
|
||||||
form.fields["deposit_type"].help_text = _("Choose how you want to pay the deposit")
|
form.fields["deposit_type"].help_text = _("Choose how you want to pay the deposit")
|
||||||
|
|
||||||
|
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.")
|
||||||
|
|
||||||
return form
|
return form
|
||||||
|
|
||||||
def get_membership_form(self, data=None, instance=None):
|
def get_membership_form(self, data=None, instance=None):
|
||||||
|
Reference in New Issue
Block a user