From a3a9dfc8124c54d0ee680fb039adad3bfe1db1c5 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 16 Sep 2021 11:00:10 +0200 Subject: [PATCH] =?UTF-8?q?[Treasury]=20Don't=20add=20non-existing=20trans?= =?UTF-8?q?actions=20to=20sog=C3=A9-credits=20(eg.=20when=20membership=20i?= =?UTF-8?q?s=20free)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yohann D'ANELLO --- apps/treasury/models.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/apps/treasury/models.py b/apps/treasury/models.py index 28351531..427d796d 100644 --- a/apps/treasury/models.py +++ b/apps/treasury/models.py @@ -331,13 +331,15 @@ class SogeCredit(models.Model): if bde_qs.exists(): m = bde_qs.get() - if m.transaction not in self.transactions.all(): - self.transactions.add(m.transaction) + if MembershipTransaction.objects.filter(membership=m).exists(): # non-free membership + if m.transaction not in self.transactions.all(): + self.transactions.add(m.transaction) if kfet_qs.exists(): m = kfet_qs.get() - if m.transaction not in self.transactions.all(): - self.transactions.add(m.transaction) + if MembershipTransaction.objects.filter(membership=m).exists(): # non-free membership + if m.transaction not in self.transactions.all(): + self.transactions.add(m.transaction) if 'wei' in settings.INSTALLED_APPS: from wei.models import WEIClub @@ -345,8 +347,9 @@ class SogeCredit(models.Model): wei_qs = Membership.objects.filter(user=self.user, club=wei, date_start__gte=wei.membership_start) if wei_qs.exists(): m = wei_qs.get() - if m.transaction not in self.transactions.all(): - self.transactions.add(m.transaction) + if MembershipTransaction.objects.filter(membership=m).exists(): # non-free membership + if m.transaction not in self.transactions.all(): + self.transactions.add(m.transaction) for tr in self.transactions.all(): tr.valid = False