From 45279aac8dc9ab5c81eb61b53700239ec1f7fa70 Mon Sep 17 00:00:00 2001 From: Patrick Mayr Date: Wed, 10 Jan 2024 10:24:48 +0000 Subject: [PATCH] add status to wiref --- fet2020/finance/admin.py | 16 ++++++++++++++++ fet2020/finance/forms.py | 3 +++ fet2020/finance/models.py | 11 +++++++++++ 3 files changed, 30 insertions(+) diff --git a/fet2020/finance/admin.py b/fet2020/finance/admin.py index 6f5b333c..7165bef8 100644 --- a/fet2020/finance/admin.py +++ b/fet2020/finance/admin.py @@ -331,10 +331,12 @@ class WirefAdmin(admin.ModelAdmin): list_display = [ "wiref_id", + "status", "file_field", "total", ] + actions = ["make_cleared", "make_finished"] ordering = ["-wiref_id"] def add_view(self, request, form_url="", extra_context=None): @@ -364,3 +366,17 @@ class WirefAdmin(admin.ModelAdmin): total += elem.amount return f"{ total }" + + @admin.action(description="Als 'Abgeschlossen' markieren.") + def make_finished(self, request, queryset): + updated = queryset.update(status=Wiref.Status.CLOSED) + self.message_user( + request, + ngettext( + "%d Wiref Formular wurde als 'Abgeschlossen' markiert.", + "%d Wiref Formulare wurden als 'Abgeschlossen' markiert.", + updated, + ) + % updated, + messages.SUCCESS, + ) diff --git a/fet2020/finance/forms.py b/fet2020/finance/forms.py index afceb2a6..1d63fdb0 100644 --- a/fet2020/finance/forms.py +++ b/fet2020/finance/forms.py @@ -373,6 +373,7 @@ class WirefAdminForm(forms.ModelForm): fields = [ "wiref_id", + "status", "file_field", "total", ] @@ -385,6 +386,8 @@ class WirefAdminForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # to get the self.fields set + self.fields["wiref_id"].required = True + wiref = kwargs.get("instance", None) total = 0 diff --git a/fet2020/finance/models.py b/fet2020/finance/models.py index 16ad3f05..2e1917a1 100644 --- a/fet2020/finance/models.py +++ b/fet2020/finance/models.py @@ -91,6 +91,17 @@ class Wiref(models.Model): verbose_name="Wiref Formular", ) + class Status(models.TextChoices): + OPENED = "O", "Offen" + CLOSED = "C", "Abgeschlossen" + + status = models.CharField( + max_length=1, + choices=Status.choices, + default=Status.OPENED, + verbose_name="Status", + ) + class Meta: verbose_name = "Wiref Formular" verbose_name_plural = "Wiref Formulare"