diff --git a/schoolapps/dashboard/models.py b/schoolapps/dashboard/models.py index 3aaf75ae4c872092683b26809d6cbbc0155da8b1..8a26ce363f72ef0867614a389fc1c7b1062ee16f 100755 --- a/schoolapps/dashboard/models.py +++ b/schoolapps/dashboard/models.py @@ -11,7 +11,7 @@ from mailer import send_mail_with_template class Activity(models.Model): user = models.ForeignKey(to=User, on_delete=models.CASCADE) - title = models.CharField(max_length=200) + title = models.CharField(max_length=150) description = models.TextField(max_length=500) app = models.CharField(max_length=100) @@ -24,7 +24,7 @@ class Activity(models.Model): class Notification(models.Model): user = models.ForeignKey(to=User, on_delete=models.CASCADE, related_name="notifications") - title = models.CharField(max_length=200) + title = models.CharField(max_length=150) description = models.TextField(max_length=500) link = models.URLField(blank=True) @@ -48,8 +48,8 @@ def register_notification(user, title, description, app="SchoolApps", link=""): class Cache(models.Model): - id = models.CharField(max_length=200, unique=True, primary_key=True, verbose_name="ID") - name = models.CharField(max_length=200, verbose_name="Name") + id = models.CharField(max_length=150, unique=True, primary_key=True, verbose_name="ID") + name = models.CharField(max_length=150, verbose_name="Name") expiration_time = models.IntegerField(default=20, verbose_name="Ablaufzeit") last_time_updated = models.DateTimeField(blank=True, null=True, verbose_name="Letzter Aktualisierungszeitpunkt des Caches") diff --git a/schoolapps/fibu/admin.py b/schoolapps/fibu/admin.py index d67d153c135af46a5712983aca76def0d67bb132..fc3ab8581a9502ffc2a06512bd242bec7d71ac5d 100644 --- a/schoolapps/fibu/admin.py +++ b/schoolapps/fibu/admin.py @@ -1,4 +1,6 @@ from django.contrib import admin -from .models import Booking +from .models import Costcenter, Account, Booking +admin.site.register(Costcenter) +admin.site.register(Account) admin.site.register(Booking) diff --git a/schoolapps/fibu/forms.py b/schoolapps/fibu/forms.py index 155845bb60c402d84d40df61108966911e3dea31..5d12a54de808af0e4de2ea62d42f6993e2ac3713 100644 --- a/schoolapps/fibu/forms.py +++ b/schoolapps/fibu/forms.py @@ -3,17 +3,47 @@ from django.core.exceptions import ValidationError from django.utils import timezone from datetime import datetime from material import Layout, Row, Fieldset -from .models import Booking, Costcenter, SCHOOLYEARLIST +from .models import YEARLIST, Booking, Costcenter, Account + + +class EditBookingForm(forms.ModelForm): + description = forms.CharField(label='Beschreibung - Was soll gekauft werden?') + planned_amount = forms.IntegerField(label='Erwarteter Betrag - Welcher Betrag ist erforderlich (in Euro ohne Komma)?') + justification = forms.CharField(label='Begründung - Begründe ggf. deinen Antrag.', required=False) + + layout = Layout(Row('description', 'planned_amount'), Row('justification')) + + class Meta: + model = Booking + fields = ('id', 'description', 'planned_amount', 'justification') + class EditCostcenterForm(forms.ModelForm): - costcenter = forms.CharField(max_length=30, label='Kostenstelle') - schoolyear = forms.ChoiceField(choices=SCHOOLYEARLIST) + name = forms.CharField(max_length=30, label='Kostenstelle') + year = forms.ChoiceField(choices=YEARLIST, label='Jahr') - layout = Layout(Row(Fieldset('Kostenstelle', 'costcenter'), Fieldset('Schuljahr', 'schoolyear'))) + layout = Layout(Row('name','year')) class Meta: model = Costcenter - fields = ('id', 'costcenter', 'schoolyear') + fields = ('id', 'name', 'year') + + +class EditAccountForm(forms.ModelForm): + costcenterlist = Costcenter.objects.filter() + costcenter_choices = [(x, val.name) for x, val in enumerate(costcenterlist)] +# print('choices:', costcenter_choices) + + name = forms.CharField(max_length=30, label='Buchungskonto') + costcenter = forms.ModelChoiceField(queryset=costcenterlist, label='Kostenstelle') + print('costcenter:', costcenter) + budget = forms.IntegerField(label='Budget') + + layout = Layout(Row('name', 'costcenter', 'budget')) + + class Meta: + model = Account + fields = ('id', 'name', 'costcenter', 'budget') # @@ -54,16 +84,3 @@ class EditCostcenterForm(forms.ModelForm): # fields = ('cost_center', 'description', 'planned_amount') -class EditBookingForm(forms.ModelForm): - description = forms.CharField(label='Was soll gekauft werden?') - planned_amount = forms.IntegerField(label='Welcher Betrag ist dafür erforderlich (Euro)?') - justification = forms.CharField(label='Begründe ggf. deinen Antrag.', required=False) - - layout = Layout(Row(Fieldset('Beschreibung', 'description'), - Fieldset('Erwarteter Betrag', 'planned_amount')), - Row(Fieldset('Begründung (optional)', 'justification'))) - - class Meta: - model = Booking - fields = ('id', 'description', 'planned_amount', 'justification') - diff --git a/schoolapps/fibu/models.py b/schoolapps/fibu/models.py index 17ebce9a1dc6031b053557e605c2b7284ed7b81b..e27c3a191f8b791c95aca981dafae4a35d2f17b1 100644 --- a/schoolapps/fibu/models.py +++ b/schoolapps/fibu/models.py @@ -1,7 +1,11 @@ from django.db import models from django.contrib.auth.models import User -SCHOOLYEARLIST = ['2019/2020','2020/2021','2021/2022','2022/2023','2023/2024'] +YEARLIST = [(2019,'2019'), + (2020,'2020'), + (2021,'2021'), + (2022,'2022'), + (2023,'2023')] class Status: def __init__(self, name, style_class): @@ -27,7 +31,10 @@ status_choices = [(x, val.name) for x, val in enumerate(status_list)] class Costcenter(models.Model): # Kostenstellen z.B. Schoolträger-konsumtiv, Schulträger-investiv, Elternberein, ... name = models.CharField(max_length=20) - schoolyear = models.CharField(max_length=20) + year = models.IntegerField(default=2019, choices=YEARLIST, verbose_name="Jahr") + def __str__(self): + return self.name + class Meta: permissions = ( ('edit_costcenter', 'Can edit cost center'), @@ -35,16 +42,16 @@ class Costcenter(models.Model): class Account(models.Model): # Buchungskonten, z.B. Fachschaften, Sekretariat, Schulleiter, Kopieren, Tafelnutzung - name = models.CharField(max_length=20) - costcenter = models.ForeignKey(to=Costcenter, on_delete=models.CASCADE) - budget = models.DecimalField(max_digits=9, decimal_places=2) + name = models.CharField(max_length=20, default='') + costcenter = models.ForeignKey(to=Costcenter, on_delete=models.CASCADE, default='') + budget = models.DecimalField(max_digits=9, decimal_places=2, default=0.00) class Meta: permissions = ( ('edit_account', 'Can edit account'), ) class Booking(models.Model): - account = models.ForeignKey(to=Account, on_delete=models.SET_NULL, blank=True, null=True) +# account = models.ForeignKey(to=Account, on_delete=models.SET_NULL, blank=True, null=True) contact = models.ForeignKey(to=User, related_name='bookings', on_delete=models.SET_NULL , verbose_name="Erstellt von", blank=True, null=True) # invoice_date = models.DateField() diff --git a/schoolapps/fibu/templates/fibu/account/edit.html b/schoolapps/fibu/templates/fibu/account/edit.html new file mode 100644 index 0000000000000000000000000000000000000000..1bcb6c7ab069c72a72bc3415c707659abcc09fbe --- /dev/null +++ b/schoolapps/fibu/templates/fibu/account/edit.html @@ -0,0 +1,23 @@ +{% include 'partials/header.html' %} +{% load material_form %} + +<main> + + <h4>Buchungskonto bearbeiten</h4> + + <form method="POST"> + {% csrf_token %} + {% form form=form %} + {% endform %} + <button type="submit" class="waves-effect waves-light btn green"> + <i class="material-icons left">send</i> Änderungen übernehmen + </button> + <a href="{% url 'account' %}"> + <button type="button" class="waves-effect waves-light btn grey"> + <i class="material-icons left">cancel</i> Abbrechen + </button> + </a> + </form> + +</main> +{% include 'partials/footer.html' %} diff --git a/schoolapps/fibu/templates/fibu/account/index.html b/schoolapps/fibu/templates/fibu/account/index.html new file mode 100755 index 0000000000000000000000000000000000000000..550a6e2df41d41dfbbf6ed2f03bacc194196a63a --- /dev/null +++ b/schoolapps/fibu/templates/fibu/account/index.html @@ -0,0 +1,49 @@ +{% include 'partials/header.html' %} +{% load material_form %} + +<main> + +{# <a href="{% url 'fibu_make_booking' %}" class="waves-effect waves-light btn green">Neuen Antrag stellen</a>#} + + {% block content %} + + <h4>Buchungskonten</h4> + <form method="POST" style="border-width: 5px; background: #eee;"> + {% csrf_token %} + {% form form=form %} + {% endform %} + <button type="submit" class="waves-effect waves-light btn green right"> + <i class="material-icons left">send</i> Buchungskonto anlegen + </button> + </form> + + <h4>Bestehende Buchungskonten</h4> + <div class="collection"> + {% for account in accounts %} + <div class="collection-item row"> + <span class="col s12 m6">{{ account.name }}</span> + <span class="col s12 m2 right-align">{{ account.costcenter }}</span> + <span class="col s12 m2 right-align">{{ account.budget }}</span> + <span class="col s12 m2 right-align"> + <form action="{% url 'account_edit' account.id %}" class="left"> + {% csrf_token %} + <input type="hidden" value="{{ account.id }}" name="account-id"> + <button type="submit" name="edit" + class="waves-effect waves-light btn-flat btn-flat-medium" title="Bearbeiten"> + <i class="material-icons center green-text">create</i> + </button> + </form> + <form action="" method="POST" class="left"> + {% csrf_token %} + <input type="hidden" value="{{ account.id }}" name="account-id"> + <button type="submit" onclick="return confirm('Wollen Sie das Buchungskonto wirklich löschen?')" name="cancel" class="waves-effect waves-light btn-flat btn-flat-medium" title="Löschen"> + <i class="material-icons center red-text">cancel</i> + </button> + </form> + </span> + </div> + {% endfor %} + </div> + {% endblock %} +</main> +{% include 'partials/footer.html' %} diff --git a/schoolapps/fibu/templates/fibu/check.html b/schoolapps/fibu/templates/fibu/booking/check.html similarity index 100% rename from schoolapps/fibu/templates/fibu/check.html rename to schoolapps/fibu/templates/fibu/booking/check.html diff --git a/schoolapps/fibu/templates/fibu/edit.html b/schoolapps/fibu/templates/fibu/booking/edit.html similarity index 100% rename from schoolapps/fibu/templates/fibu/edit.html rename to schoolapps/fibu/templates/fibu/booking/edit.html diff --git a/schoolapps/fibu/templates/fibu/costcenter/edit.html b/schoolapps/fibu/templates/fibu/costcenter/edit.html new file mode 100644 index 0000000000000000000000000000000000000000..7dc11ec82047bb08a4ce4261dc3ac3010e6cc175 --- /dev/null +++ b/schoolapps/fibu/templates/fibu/costcenter/edit.html @@ -0,0 +1,23 @@ +{% include 'partials/header.html' %} +{% load material_form %} + +<main> + + <h4>Kostenstelle bearbeiten</h4> + + <form method="POST"> + {% csrf_token %} + {% form form=form %} + {% endform %} + <button type="submit" class="waves-effect waves-light btn green"> + <i class="material-icons left">send</i> Änderungen übernehmen + </button> + <a href="{% url 'costcenter' %}"> + <button type="button" class="waves-effect waves-light btn grey"> + <i class="material-icons left">cancel</i> Abbrechen + </button> + </a> + </form> + +</main> +{% include 'partials/footer.html' %} diff --git a/schoolapps/fibu/templates/fibu/costcenter.html b/schoolapps/fibu/templates/fibu/costcenter/index.html similarity index 95% rename from schoolapps/fibu/templates/fibu/costcenter.html rename to schoolapps/fibu/templates/fibu/costcenter/index.html index 480e15c025a3cdf7054e0d016f37c8285f376de7..ae8e40a9bfc6a70ae358c515cd762d96cf488107 100755 --- a/schoolapps/fibu/templates/fibu/costcenter.html +++ b/schoolapps/fibu/templates/fibu/costcenter/index.html @@ -8,11 +8,11 @@ {% block content %} <h4>Kostenstellen</h4> - <form method="POST" style="border-width: 5px;"> + <form method="POST" style="border-width: 5px; background: #eee;"> {% csrf_token %} {% form form=form %} {% endform %} - <button type="submit" class="waves-effect waves-light btn green"> + <button type="submit" class="waves-effect waves-light btn green right"> <i class="material-icons left">send</i> Kostenstelle anlegen </button> </form> @@ -22,7 +22,7 @@ {% for costcenter in costcenterlist %} <div class="collection-item row"> <span class="col s12 m8">{{ costcenter.name }}</span> - <span class="col s12 m2 right-align">{{ costcenter.schoolyear }} €</span> + <span class="col s12 m2 right-align">{{ costcenter.year }}</span> <span class="col s12 m2 right-align"> <form action="{% url 'costcenter_edit' costcenter.id %}" class="left"> {% csrf_token %} diff --git a/schoolapps/fibu/templates/fibu/index.html b/schoolapps/fibu/templates/fibu/index.html index 56aed0b4c1c330cee3530d05aff17d85e8d3a93e..9e72faab510181e6ab86fe841c1450fe16208c38 100755 --- a/schoolapps/fibu/templates/fibu/index.html +++ b/schoolapps/fibu/templates/fibu/index.html @@ -8,11 +8,11 @@ {% block content %} <h4>Beantragungen von {{ user }}</h4> - <form method="POST" style="border-width: 5px;"> + <form method="POST" style="border-width: 5px; background: #eee"> {% csrf_token %} {% form form=form %} {% endform %} - <button type="submit" class="waves-effect waves-light btn green"> + <button type="submit" class="waves-effect waves-light btn green right"> <i class="material-icons left">send</i> Antrag stellen </button> </form> diff --git a/schoolapps/fibu/urls.py b/schoolapps/fibu/urls.py index faf15d86cb510177b68512fc766d31e5089f9a29..767aa14662497f61d70eba7a00aaaee7996f5b8d 100755 --- a/schoolapps/fibu/urls.py +++ b/schoolapps/fibu/urls.py @@ -5,8 +5,11 @@ from . import views urlpatterns = [ path('', views.index, name='fibu_index'), path('check', views.check, name='booking_check'), - path('costcenter', views.costcenter, name='costcenter'), path('edit/<int:id>', views.edit, name='booking_edit'), + path('costcenter', views.costcenter, name='costcenter'), + path('costcenter/edit/<int:id>', views.costcenter_edit, name='costcenter_edit'), + path('account', views.account, name='account'), + path('account/edit/<int:id>', views.account_edit, name='account_edit'), # path('make_booking', views.make_booking, name='fibu_make_booking'), # path('edit/<int:id>', views.edit, name='booking_edit'), ] diff --git a/schoolapps/fibu/views.py b/schoolapps/fibu/views.py index a5a11fc6b20d547980170dcc65701a1263626443..36bc2c26be08a75e6f7cc9e02cd1e6afdd2ad556 100644 --- a/schoolapps/fibu/views.py +++ b/schoolapps/fibu/views.py @@ -1,9 +1,9 @@ from django.contrib.auth.decorators import login_required, permission_required from django.urls import reverse from django.shortcuts import render, redirect, get_object_or_404 -from .models import Booking, Costcenter +from .models import Booking, Costcenter, Account from .filters import BookingFilter -from .forms import EditBookingForm, EditCostcenterForm +from .forms import EditBookingForm, EditCostcenterForm, EditAccountForm @login_required @@ -35,11 +35,10 @@ def index(request): else: form = EditBookingForm() if form.is_valid(): - account = '' description = form.cleaned_data['description'] planned_amount = form.cleaned_data['planned_amount'] justification = form.cleaned_data['justification'] - booking = Booking(account=account, description=description, planned_amount=planned_amount, contact=request.user, justification=justification) + booking = Booking(description=description, planned_amount=planned_amount, contact=request.user, justification=justification) booking.save() # a = Activity(user=request.user, title="Antrag auf Unterrichtsbefreiung gestellt", @@ -102,7 +101,7 @@ def check(request): booking_list = Booking.objects.filter(status=0).order_by('submission_date') bookings = BookingFilter(request.GET, queryset=booking_list) - return render(request, 'fibu/check.html', {'filter': bookings}) + return render(request, 'fibu/booking/check.html', {'filter': bookings}) @login_required @@ -129,8 +128,8 @@ def costcenter(request): form = EditCostcenterForm() if form.is_valid(): name = form.cleaned_data['name'] - schoolyear = form.cleaned_data['schoolyear'] - costcenter = Costcenter(name=name, schoolyear=schoolyear) + year = form.cleaned_data['year'] + costcenter = Costcenter(name=name, year=year) costcenter.save() # a = Activity(user=request.user, title="Antrag auf Unterrichtsbefreiung gestellt", @@ -140,6 +139,91 @@ def costcenter(request): # a.save() # return redirect('fibu_make_booking') return redirect('costcenter') - costcenter = Costcenter.objects.filter() - context = {'costcenter': costcenter, 'form': form} - return render(request, 'fibu/costcenter.html', context) + costcenterlist = Costcenter.objects.filter() + context = {'costcenterlist': costcenterlist, 'form': form} + return render(request, 'fibu/costcenter/index.html', context) + + +@login_required +# @permission_required('aub.apply_for_aub') +def costcenter_edit(request, id): + costcenter = get_object_or_404(Costcenter, id=id) + form = EditCostcenterForm(instance=costcenter) + template = 'fibu/costcenter/edit.html' + if request.method == 'POST': + form = EditCostcenterForm(request.POST, instance=costcenter) + print('\n\n\nBLUBB', form) + if form.is_valid(): + form.save() + # a = Activity(user=request.user, title="Antrag auf Unterrichtsbefreiung verändert", + # description="Sie haben Ihren Antrag auf Unterrichtsbefreiung " + + # "für den Zeitraum von {} bis {} bearbeitet.".format( + # aub.from_date, aub.to_date), app=AubConfig.verbose_name) + # a.save() + + return redirect(reverse('costcenter')) + context = {'form': form} + return render(request, template, context) + +@login_required +#@permission_required('fibu.view_booking') +def account(request): + if request.method == 'POST': + if 'account-id' in request.POST: + account_id = request.POST['account-id'] + account = Account.objects.get(id=account_id) + if 'cancel' in request.POST: + account.delete() +# a = Activity(user=aub_user, title="Antrag auf Unterrichtsbefreiung gelöscht", +# description="Sie haben Ihren Antrag auf Unterrichtsbefreiung " + +# "für den Zeitraum von {} bis {} gelöscht.".format( +# aub.from_date, aub.to_date), app=AubConfig.verbose_name) +# a.save() + print('Eintrag gelöscht') + return redirect('account') + print('Edit-Form erstellt ############# form.is_valid:', form.is_valid()) + form = EditAccountForm(instance=account) + else: + form = EditAccountForm(request.POST or None) + else: + form = EditAccountForm() + if form.is_valid(): + name = form.cleaned_data['name'] + costcenter = form.cleaned_data['costcenter'] + budget = form.cleaned_data['budget'] + account = Account(name=name, costcenter=costcenter, budget=budget) + account.save() + + # a = Activity(user=request.user, title="Antrag auf Unterrichtsbefreiung gestellt", + # description="Sie haben einen Antrag auf Unterrichtsbefreiung " + + # "für den Zeitraum von {} bis {} gestellt.".format( + # aub.from_date, aub.to_date), app=AubConfig.verbose_name) + # a.save() + # return redirect('fibu_make_booking') + return redirect('account') + accounts = Account.objects.filter() + context = {'accounts': accounts, 'form': form} + return render(request, 'fibu/account/index.html', context) + + +@login_required +# @permission_required('aub.apply_for_aub') +def account_edit(request, id): + account = get_object_or_404(Account, id=id) + form = EditAccountForm(instance=account) + template = 'fibu/account/edit.html' + if request.method == 'POST': + form = EditAccountForm(request.POST, instance=account) + print('\n\n\nBLUBB', form) + if form.is_valid(): + form.save() + # a = Activity(user=request.user, title="Antrag auf Unterrichtsbefreiung verändert", + # description="Sie haben Ihren Antrag auf Unterrichtsbefreiung " + + # "für den Zeitraum von {} bis {} bearbeitet.".format( + # aub.from_date, aub.to_date), app=AubConfig.verbose_name) + # a.save() + + return redirect(reverse('account')) + context = {'form': form} + return render(request, template, context) + diff --git a/schoolapps/templates/partials/header.html b/schoolapps/templates/partials/header.html index a16f16e928094dfff2cf8a222447979751cef7c8..391d3167c2200428ba502091c557b9160efbb796 100755 --- a/schoolapps/templates/partials/header.html +++ b/schoolapps/templates/partials/header.html @@ -184,12 +184,15 @@ </a> <div class="collapsible-body"> <ul class="collapsible collapsible-accordion"> - <div class="url-booking_check1"> + <div> <li><a href="{% url 'booking_check' %}"><i class="material-icons">done</i>Buchungen prüfen</a></li> </div> - <div class="url-booking_check2"> + <div> <li><a href="{% url 'costcenter' %}"><i class="material-icons">done</i>Kostenstellen</a></li> </div> + <div> + <li><a href="{% url 'account' %}"><i class="material-icons">done</i>Buchungskonten</a></li> + </div> </ul> </div> </li>