1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-02-24 17:11:18 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
a3a9dfc812
[Treasury] Don't add non-existing transactions to sogé-credits (eg. when membership is free)
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
2021-09-16 11:00:10 +02:00
76531595ad
80 € for people that opened an account to Société générale and don't go to the WEI
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
2021-09-16 10:58:23 +02:00

View File

@ -1,6 +1,6 @@
# Copyright (C) 2018-2021 by BDE ENS Paris-Saclay # Copyright (C) 2018-2021 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import datetime
from datetime import date from datetime import date
from django.conf import settings from django.conf import settings
@ -305,8 +305,16 @@ class SogeCredit(models.Model):
@property @property
def amount(self): def amount(self):
return self.credit_transaction.total if self.valid \ if self.valid:
else sum(transaction.total for transaction in self.transactions.all()) return self.credit_transaction.total
amount = sum(transaction.total for transaction in self.transactions.all())
if 'wei' in settings.INSTALLED_APPS:
from wei.models import WEIMembership
if not WEIMembership.objects.filter(club__weiclub__year=datetime.date.today().year, user=self.user)\
.exists():
# 80 € for people that don't go to WEI
amount += 8000
return amount
def update_transactions(self): def update_transactions(self):
""" """
@ -323,11 +331,13 @@ class SogeCredit(models.Model):
if bde_qs.exists(): if bde_qs.exists():
m = bde_qs.get() m = bde_qs.get()
if MembershipTransaction.objects.filter(membership=m).exists(): # non-free membership
if m.transaction not in self.transactions.all(): if m.transaction not in self.transactions.all():
self.transactions.add(m.transaction) self.transactions.add(m.transaction)
if kfet_qs.exists(): if kfet_qs.exists():
m = kfet_qs.get() m = kfet_qs.get()
if MembershipTransaction.objects.filter(membership=m).exists(): # non-free membership
if m.transaction not in self.transactions.all(): if m.transaction not in self.transactions.all():
self.transactions.add(m.transaction) self.transactions.add(m.transaction)
@ -337,6 +347,7 @@ class SogeCredit(models.Model):
wei_qs = Membership.objects.filter(user=self.user, club=wei, date_start__gte=wei.membership_start) wei_qs = Membership.objects.filter(user=self.user, club=wei, date_start__gte=wei.membership_start)
if wei_qs.exists(): if wei_qs.exists():
m = wei_qs.get() m = wei_qs.get()
if MembershipTransaction.objects.filter(membership=m).exists(): # non-free membership
if m.transaction not in self.transactions.all(): if m.transaction not in self.transactions.all():
self.transactions.add(m.transaction) self.transactions.add(m.transaction)