added costs
This commit is contained in:
parent
83beefd23d
commit
8288902cc0
18 changed files with 378 additions and 10 deletions
|
@ -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"),
|
||||
}
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -55,6 +55,7 @@ INSTALLED_APPS = [
|
|||
# -----------------------------------
|
||||
"aviary",
|
||||
"bird",
|
||||
"costs",
|
||||
"rescuer",
|
||||
"sites",
|
||||
]
|
||||
|
|
|
@ -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
|
||||
|
|
0
app/costs/__init__.py
Normal file
0
app/costs/__init__.py
Normal file
14
app/costs/admin.py
Normal file
14
app/costs/admin.py
Normal file
|
@ -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")
|
8
app/costs/apps.py
Normal file
8
app/costs/apps.py
Normal file
|
@ -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")
|
29
app/costs/forms.py
Normal file
29
app/costs/forms.py
Normal file
|
@ -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"),
|
||||
}
|
34
app/costs/migrations/0001_initial.py
Normal file
34
app/costs/migrations/0001_initial.py
Normal file
|
@ -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',
|
||||
},
|
||||
),
|
||||
]
|
0
app/costs/migrations/__init__.py
Normal file
0
app/costs/migrations/__init__.py
Normal file
39
app/costs/models.py
Normal file
39
app/costs/models.py
Normal file
|
@ -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")
|
77
app/costs/templates/costs/costs_all.html
Normal file
77
app/costs/templates/costs/costs_all.html
Normal file
|
@ -0,0 +1,77 @@
|
|||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
{% block header %}
|
||||
<!-- Datatable CSS -->
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/dataTables.bootstrap5.min.css" />
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/responsive/2.2.9/css/responsive.bootstrap5.min.css">
|
||||
|
||||
<!-- Font Awesome -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||
|
||||
<!-- jQuery -->
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
|
||||
|
||||
<!-- Datatable jQuery -->
|
||||
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.11.3/js/dataTables.bootstrap5.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/responsive/2.2.9/js/dataTables.responsive.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/responsive/2.2.9/js/responsive.bootstrap5.min.js"></script>
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('#t__costs_all').DataTable({
|
||||
language: {
|
||||
url: 'https://cdn.datatables.net/plug-ins/1.11.3/i18n/de_de.json',
|
||||
},
|
||||
paging: false,
|
||||
info: false,
|
||||
responsive: true,
|
||||
columnDefs: [
|
||||
{ responsivePriority: 1, targets: 0 },
|
||||
]
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
{% endblock header %}
|
||||
{% block content %}
|
||||
<h3>Übersicht aller Kosten</h3>
|
||||
<p>
|
||||
Die Übersicht aller enstandenen Kosten.
|
||||
</p>
|
||||
<p>
|
||||
<a href="{% url 'costs_create' %}" class="btn btn-primary">Eine Buchung anlegen</a>
|
||||
</p>
|
||||
|
||||
<table class="table table-striped table-hover display responsive nowrap" width="100%" id="t__costs_all">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Patient</th>
|
||||
<th>Kosten</th>
|
||||
<th>Gebucht am</th>
|
||||
<th>Bemerkung</th>
|
||||
<th>Benutzer</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for item in costs %}
|
||||
<tr>
|
||||
<td> {{item.id_bird}} </td>
|
||||
<td> {{item.costs}} </td>
|
||||
<td> {{item.created}} </td>
|
||||
<td> {{item.comment}} </td>
|
||||
<td> {{item.user}} </td>
|
||||
<td><a href="{% url 'costs_edit' item.id %}"><i class="fa-sharp fa-solid fa-pen"></i></a></td>
|
||||
<td><a href="{% url 'costs_delete' item.id %}"><i class="fa-sharp fa-solid fa-trash"></i></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
{% endblock content %}
|
||||
|
55
app/costs/templates/costs/costs_delete.html
Normal file
55
app/costs/templates/costs/costs_delete.html
Normal file
|
@ -0,0 +1,55 @@
|
|||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% block content %}
|
||||
<h3>Buchung löschen</h3>
|
||||
<p></p>
|
||||
<div class="row">
|
||||
<div class="col-lg-5 mb-3">
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<fieldset>
|
||||
{% csrf_token %}
|
||||
<div class="card bg-light mb-3" style="max-width: 30rem;">
|
||||
<div class="card-header">Buchung</div>
|
||||
<div class="card-body">
|
||||
<p class="card-text">
|
||||
<strong>Patient:</strong> {{costs.id_bird}}<br>
|
||||
<strong>Buchung:</strong> {{costs.costs}}<br>
|
||||
<strong>Gebucht am:</strong> {{costs.created}}<br>
|
||||
<strong>Bemerkung:</strong> {{costs.comment|default_if_none:"keine Bemerkung"}}<br>
|
||||
<strong>Nutzer:</strong> {{costs.user}}<br>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-success" type="abbort">Abbrechen</button>
|
||||
<button class="btn btn-danger" type="submit">Löschen</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-5">
|
||||
<h4>
|
||||
Kennung
|
||||
</h4>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
<h4>
|
||||
Vogel
|
||||
</h4>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="{% static 'js/bird.js' %}"></script>
|
||||
|
||||
{% endblock content %}
|
44
app/costs/templates/costs/costs_edit.html
Normal file
44
app/costs/templates/costs/costs_edit.html
Normal file
|
@ -0,0 +1,44 @@
|
|||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% block content %}
|
||||
<h3>Buchung bearbeiten</h3>
|
||||
<p></p>
|
||||
<div class="row">
|
||||
<div class="col-lg-5 mb-3">
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<fieldset>
|
||||
{% csrf_token %}
|
||||
{{form|crispy}}
|
||||
<button class="btn btn-success" type="abbort">Abbrechen</button>
|
||||
<button class="btn btn-primary" type="submit">Speichern</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-5">
|
||||
<h4>
|
||||
Kennung
|
||||
</h4>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
<h4>
|
||||
Vogel
|
||||
</h4>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="{% static 'js/bird.js' %}"></script>
|
||||
|
||||
{% endblock content %}
|
3
app/costs/tests.py
Normal file
3
app/costs/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
15
app/costs/urls.py
Normal file
15
app/costs/urls.py
Normal file
|
@ -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/<id>", costs_edit, name="costs_edit"),
|
||||
path("delete/<id>", costs_delete, name="costs_delete"),
|
||||
]
|
44
app/costs/views.py
Normal file
44
app/costs/views.py
Normal file
|
@ -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")
|
|
@ -26,6 +26,10 @@
|
|||
<a class="nav-link {% if '/aviary/all' in request.path %} active {% endif %}"
|
||||
href="{% url 'aviary_all' %}">alle Volieren</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if '/costs/all' in request.path %} active {% endif %}"
|
||||
href="{% url 'costs_all' %}">Kosten</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue