From 0234f19a3383ffc97fe94a3e30c06d0738d3e47e Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 14 Sep 2021 13:44:52 +0200 Subject: [PATCH] [WEI] Automatically indicate a soge credit if already created Signed-off-by: Yohann D'ANELLO --- apps/wei/views.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/wei/views.py b/apps/wei/views.py index b60b4a73..80ff770e 100644 --- a/apps/wei/views.py +++ b/apps/wei/views.py @@ -7,6 +7,7 @@ import subprocess from datetime import date, timedelta from tempfile import mkdtemp +from django.conf import settings from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.models import User from django.core.exceptions import PermissionDenied @@ -555,6 +556,12 @@ class WEIRegister1AView(ProtectQuerysetMixin, ProtectedCreateView): " participated to a WEI.")) return self.form_invalid(form) + if 'treasury' in settings.INSTALLED_APPS: + from treasury.models import SogeCredit + form.instance.soge_credit = \ + form.instance.soge_credit \ + or SogeCredit.objects.filter(user=form.instance.user, credit_transaction__valid=False).exists() + return super().form_valid(form) def get_success_url(self): @@ -656,6 +663,12 @@ class WEIRegister2AView(ProtectQuerysetMixin, ProtectedCreateView): form.instance.information = information form.instance.save() + if 'treasury' in settings.INSTALLED_APPS: + from treasury.models import SogeCredit + form.instance.soge_credit = \ + form.instance.soge_credit \ + or SogeCredit.objects.filter(user=form.instance.user, credit_transaction__valid=False).exists() + return super().form_valid(form) def get_success_url(self):