diff --git a/app/bird/forms.py b/app/bird/forms.py index 3901b7e..055ae60 100644 --- a/app/bird/forms.py +++ b/app/bird/forms.py @@ -27,7 +27,7 @@ class BirdAddForm(forms.ModelForm): "place", "find_circumstances", "diagnostic_finding", - "costs", + # "costs", # "find_circumstances_new", # "status", ] @@ -38,7 +38,7 @@ class BirdAddForm(forms.ModelForm): "place": _("Fundort"), "find_circumstances": _("Fundumstände"), "diagnostic_finding": _("Diagnose bei Fund"), - "costs": _("Kosten"), + # "costs": _("Kosten"), # "find_circumstances_new": _("neuer Fundumstand"), # "status": _("Status"), } @@ -58,7 +58,7 @@ class BirdEditForm(forms.ModelForm): "sent_to", "find_circumstances", "diagnostic_finding", - "costs", + # "costs", ] labels = { "bird": _("Vogel"), @@ -69,5 +69,5 @@ class BirdEditForm(forms.ModelForm): "sent_to": _("Übermittelt nach"), "find_circumstances": _("Fundumstände"), "diagnostic_finding": _("Diagnose bei Fund"), - "costs": _("Kosten"), + # "costs": _("Kosten"), } diff --git a/app/bird/models.py b/app/bird/models.py index 31bf1e2..76d724a 100644 --- a/app/bird/models.py +++ b/app/bird/models.py @@ -28,9 +28,9 @@ class FallenBird(models.Model): diagnostic_finding = models.CharField( max_length=256, verbose_name=_("Diagnose bei Fund") ) - costs = models.DecimalField( - max_digits=5, decimal_places=2, default="0.00", verbose_name=_("Kosten") - ) + # costs = models.DecimalField( + # max_digits=5, decimal_places=2, default="0.00", verbose_name=_("Kosten") + # ) rescuer = models.ForeignKey( Rescuer, on_delete=models.SET_NULL, @@ -58,7 +58,7 @@ class FallenBird(models.Model): verbose_name_plural = _("Patienten") def __str__(self): - return self.place + return self.bird_identifier class Bird(models.Model): diff --git a/app/core/settings.py b/app/core/settings.py index a9f586f..6ee4a98 100644 --- a/app/core/settings.py +++ b/app/core/settings.py @@ -55,6 +55,7 @@ INSTALLED_APPS = [ # ----------------------------------- "aviary", "bird", + "costs", "rescuer", "sites", ] diff --git a/app/core/urls.py b/app/core/urls.py index 92e09b7..701baa5 100644 --- a/app/core/urls.py +++ b/app/core/urls.py @@ -19,9 +19,10 @@ from django.urls import path, include urlpatterns = [ # Dynamic sites - path("bird/", include("bird.urls")), - path("rescuer/", include("rescuer.urls")), path("aviary/", include("aviary.urls")), + path("bird/", include("bird.urls")), + path("costs/", include("costs.urls")), + path("rescuer/", include("rescuer.urls")), # Admin path("admin/", admin.site.urls), # Allauth diff --git a/app/costs/__init__.py b/app/costs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/costs/admin.py b/app/costs/admin.py new file mode 100644 index 0000000..747dbde --- /dev/null +++ b/app/costs/admin.py @@ -0,0 +1,14 @@ +from django.contrib import admin + +from .models import Costs + +@admin.register(Costs) +class FallenBirdAdmin(admin.ModelAdmin): + list_display = [ + "id_bird", + "costs", + "created", + "comment", + "user", + ] + list_filter = ("id_bird", "created") diff --git a/app/costs/apps.py b/app/costs/apps.py new file mode 100644 index 0000000..27404ab --- /dev/null +++ b/app/costs/apps.py @@ -0,0 +1,8 @@ +from django.apps import AppConfig +from django.utils.translation import gettext_lazy as _ + + +class CostsConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'costs' + verbose_name = _("Kosten") diff --git a/app/costs/forms.py b/app/costs/forms.py new file mode 100644 index 0000000..2c073fb --- /dev/null +++ b/app/costs/forms.py @@ -0,0 +1,29 @@ +from datetime import date +from django import forms +from django.utils.translation import gettext_lazy as _ + +from .models import Costs + + +class DateInput(forms.DateInput): + input_type = "date" + + +class CostsForm(forms.ModelForm): + class Meta: + widgets = { + "created": DateInput(format="%Y-%m-%d", attrs={"value": date.today}) + } + model = Costs + fields = [ + "id_bird", + "costs", + "comment", + "created" + ] + labels = { + "id_bird": _("Patient"), + "costs": _("Betrag"), + "comment": _("Bemerkung"), + "created": _("Gebucht am"), + } diff --git a/app/costs/migrations/0001_initial.py b/app/costs/migrations/0001_initial.py new file mode 100644 index 0000000..bf172cc --- /dev/null +++ b/app/costs/migrations/0001_initial.py @@ -0,0 +1,34 @@ +# Generated by Django 4.2.3 on 2023-07-13 09:34 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('bird', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Costs', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('costs', models.DecimalField(decimal_places=2, default='0.00', max_digits=5, verbose_name='Kosten')), + ('created', models.DateTimeField(auto_now_add=True, verbose_name='angelegt am')), + ('comment', models.CharField(blank=True, max_length=512, null=True, verbose_name='Bemerkungen')), + ('id_bird', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='bird.fallenbird', verbose_name='Patient')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Benutzer')), + ], + options={ + 'verbose_name': 'Kosten', + 'verbose_name_plural': 'Kosten', + }, + ), + ] diff --git a/app/costs/migrations/__init__.py b/app/costs/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/costs/models.py b/app/costs/models.py new file mode 100644 index 0000000..8ff8ecb --- /dev/null +++ b/app/costs/models.py @@ -0,0 +1,39 @@ +from datetime import date +from uuid import uuid4 + +from django.db import models +from django.conf import settings +from django.utils.translation import gettext_lazy as _ + +from bird.models import FallenBird + + +class Costs(models.Model): + id = models.UUIDField(primary_key=True, default=uuid4, editable=False) + id_bird = models.ForeignKey( + FallenBird, + on_delete=models.SET_NULL, + blank=True, + null=True, + verbose_name=_("Patient"), + ) + costs = models.DecimalField( + max_digits=5, + decimal_places=2, + default="0.00", + verbose_name=_("Betrag")) + created = models.DateTimeField( + verbose_name=_("Gebucht am")) + comment = models.CharField( + max_length=512, + blank=True, + null=True, + verbose_name=_("Bemerkungen")) + user = models.ForeignKey( + settings.AUTH_USER_MODEL, + on_delete=models.CASCADE, + verbose_name=_("Benutzer")) + + class Meta: + verbose_name = _("Kosten") + verbose_name_plural = _("Kosten") diff --git a/app/costs/templates/costs/costs_all.html b/app/costs/templates/costs/costs_all.html new file mode 100644 index 0000000..38ae578 --- /dev/null +++ b/app/costs/templates/costs/costs_all.html @@ -0,0 +1,77 @@ +{% extends "base.html" %} +{% load static %} +{% block header %} + + + + + + + + + + + + + + + + + + + + +{% endblock header %} +{% block content %} +

Übersicht aller Kosten

+

+ Die Übersicht aller enstandenen Kosten. +

+

+ Eine Buchung anlegen +

+ + + + + + + + + + + + + + + {% for item in costs %} + + + + + + + + + + {% endfor %} + +
PatientKostenGebucht amBemerkungBenutzer
{{item.id_bird}} {{item.costs}} {{item.created}} {{item.comment}} {{item.user}}
+ + + {% endblock content %} + diff --git a/app/costs/templates/costs/costs_delete.html b/app/costs/templates/costs/costs_delete.html new file mode 100644 index 0000000..1dac872 --- /dev/null +++ b/app/costs/templates/costs/costs_delete.html @@ -0,0 +1,55 @@ +{% extends "base.html" %} +{% load static %} +{% load crispy_forms_tags %} +{% block content %} +

Buchung löschen

+

+
+
+
+
+ {% csrf_token %} +
+
Buchung
+
+

+ Patient: {{costs.id_bird}}
+ Buchung: {{costs.costs}}
+ Gebucht am: {{costs.created}}
+ Bemerkung: {{costs.comment|default_if_none:"keine Bemerkung"}}
+ Nutzer: {{costs.user}}
+

+
+
+ + +
+
+
+ +
+

+ Kennung +

+

+ Lorem ipsum dolor sit, amet consectetur adipisicing elit. + Reiciendis, hic enim pariatur, exercitationem, repellat quasi sit + temporibus dicta voluptate in voluptates. Alias deserunt sint + suscipit explicabo et. Perferendis, dolor praesentium. +

+

+ Vogel +

+

+ Lorem ipsum dolor sit, amet consectetur adipisicing elit. + Reiciendis, hic enim pariatur, exercitationem, repellat quasi sit + temporibus dicta voluptate in voluptates. Alias deserunt sint + suscipit explicabo et. Perferendis, dolor praesentium. +

+ +
+
+ + + +{% endblock content %} \ No newline at end of file diff --git a/app/costs/templates/costs/costs_edit.html b/app/costs/templates/costs/costs_edit.html new file mode 100644 index 0000000..784f87e --- /dev/null +++ b/app/costs/templates/costs/costs_edit.html @@ -0,0 +1,44 @@ +{% extends "base.html" %} +{% load static %} +{% load crispy_forms_tags %} +{% block content %} +

Buchung bearbeiten

+

+
+
+
+
+ {% csrf_token %} + {{form|crispy}} + + +
+
+
+ +
+

+ Kennung +

+

+ Lorem ipsum dolor sit, amet consectetur adipisicing elit. + Reiciendis, hic enim pariatur, exercitationem, repellat quasi sit + temporibus dicta voluptate in voluptates. Alias deserunt sint + suscipit explicabo et. Perferendis, dolor praesentium. +

+

+ Vogel +

+

+ Lorem ipsum dolor sit, amet consectetur adipisicing elit. + Reiciendis, hic enim pariatur, exercitationem, repellat quasi sit + temporibus dicta voluptate in voluptates. Alias deserunt sint + suscipit explicabo et. Perferendis, dolor praesentium. +

+ +
+
+ + + +{% endblock content %} \ No newline at end of file diff --git a/app/costs/tests.py b/app/costs/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/app/costs/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/app/costs/urls.py b/app/costs/urls.py new file mode 100644 index 0000000..9fb11a5 --- /dev/null +++ b/app/costs/urls.py @@ -0,0 +1,15 @@ +from django.urls import path + +from .views import ( + costs_all, + costs_create, + costs_edit, + costs_delete, +) + +urlpatterns = [ + path("all/", costs_all, name="costs_all"), + path("create/", costs_create, name="costs_create"), + path("edit/", costs_edit, name="costs_edit"), + path("delete/", costs_delete, name="costs_delete"), +] diff --git a/app/costs/views.py b/app/costs/views.py new file mode 100644 index 0000000..7c32893 --- /dev/null +++ b/app/costs/views.py @@ -0,0 +1,44 @@ +from django.contrib.auth.decorators import login_required +from django.shortcuts import render, redirect +from .models import Costs +from .forms import CostsForm + +@login_required(login_url="account_login") +def costs_all(request): + costs = Costs.objects.all() + context = {"costs": costs} + return render(request, "costs/costs_all.html", context) + + +@login_required(login_url="account_login") +def costs_edit(request, id): + costs = Costs.objects.get(id=id) + form = CostsForm(request.POST or None, instance=costs) + if request.method == "POST": + if form.is_valid(): + form.save() + return redirect("costs_all") + + context = {"costs": costs, "form": form} + return render(request, "costs/costs_edit.html", context) + +@login_required(login_url="account_login") +def costs_delete(request, id): + costs = Costs.objects.get(id=id) + form = CostsForm(request.POST or None, instance=costs) + if request.method == "POST": + costs.delete() + return redirect("costs_all") + context = {"costs": costs} + return render(request, "costs/costs_delete.html", context) + +@login_required(login_url="account_login") +def costs_create(request): + form = CostsForm() + if request.method == "POST": + form = CostsForm(request.POST or None) + if form.is_valid(): + fs = form.save(commit=False) + fs.user = request.user + fs.save() + return render(request, "costs/costs_all.html") \ No newline at end of file diff --git a/app/templates/partials/_navbar.html b/app/templates/partials/_navbar.html index f7f504b..c130aa1 100644 --- a/app/templates/partials/_navbar.html +++ b/app/templates/partials/_navbar.html @@ -26,6 +26,10 @@ alle Volieren + {% endif %}