diff --git a/biscuit/apps/fibu/forms.py b/biscuit/apps/fibu/forms.py index 63c0ef34f1b7ed42d8c1977eb91564b6ddbde182..155845bb60c402d84d40df61108966911e3dea31 100644 --- a/biscuit/apps/fibu/forms.py +++ b/biscuit/apps/fibu/forms.py @@ -3,10 +3,19 @@ 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 +from .models import Booking, Costcenter, SCHOOLYEARLIST + +class EditCostcenterForm(forms.ModelForm): + costcenter = forms.CharField(max_length=30, label='Kostenstelle') + schoolyear = forms.ChoiceField(choices=SCHOOLYEARLIST) + + layout = Layout(Row(Fieldset('Kostenstelle', 'costcenter'), Fieldset('Schuljahr', 'schoolyear'))) + + class Meta: + model = Costcenter + fields = ('id', 'costcenter', 'schoolyear') + -# class AddCostCenterForm(forms.ModelForm): -# cost_center = forms.CharField(max_length=30, label='Kostenstelle') # # class AcquisitionForm(forms.ModelForm): # # Cost_center choices diff --git a/biscuit/apps/fibu/models.py b/biscuit/apps/fibu/models.py index e52cec8d56d7ded45d5cc3ba15561943812c735b..17ebce9a1dc6031b053557e605c2b7284ed7b81b 100644 --- a/biscuit/apps/fibu/models.py +++ b/biscuit/apps/fibu/models.py @@ -1,6 +1,8 @@ from django.db import models from django.contrib.auth.models import User +SCHOOLYEARLIST = ['2019/2020','2020/2021','2021/2022','2022/2023','2023/2024'] + class Status: def __init__(self, name, style_class): self.name = name @@ -20,44 +22,42 @@ status_list = [ status_choices = [(x, val.name) for x, val in enumerate(status_list)] -class CostCenter(models.Model): - name = models.CharField(max_length=20, primary_key=True, unique=True) + + +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) class Meta: permissions = ( ('edit_costcenter', 'Can edit cost center'), ) class Account(models.Model): - number = models.IntegerField(primary_key=True, unique=True) + # 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) class Meta: permissions = ( ('edit_account', 'Can edit account'), ) -class Budget(models.Model): - name = models.CharField(max_length=30, primary_key=True, unique=True) - class Meta: - permissions = ( - ('edit_budget', 'Can edit budget'), - ) - class Booking(models.Model): -# cost_center = models.ForeignKey(CostCenter, on_delete=models.CASCADE) - contact = models.ForeignKey(User, related_name='bookings', on_delete=models.SET_NULL + 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() # invoice_number = models.CharField(max_length=20) # firma = models.CharField(max_length=30) description = models.CharField(max_length=50) -# amount = models.DecimalField(max_digits=10, decimal_places=2) +# amount = models.DecimalField(max_digits=9, decimal_places=2) planned_amount = models.IntegerField() submission_date = models.DateField(default='2019-01-01') justification = models.CharField(max_length=2000, blank=True, null=True) # payout_number = models.IntegerField() # booking_date = models.DateField() # maturity = models.DateField() -# account = models.ForeignKey(Account, on_delete=models.CASCADE) -# budget = models.ForeignKey(Budget, on_delete=models.CASCADE) # upload = models.FileField(upload_to='uploads/fibu/%Y/') status = models.IntegerField(default=0, choices=status_choices, verbose_name="Status") diff --git a/biscuit/apps/fibu/templates/fibu/costcenter.html b/biscuit/apps/fibu/templates/fibu/costcenter.html new file mode 100755 index 0000000000000000000000000000000000000000..480e15c025a3cdf7054e0d016f37c8285f376de7 --- /dev/null +++ b/biscuit/apps/fibu/templates/fibu/costcenter.html @@ -0,0 +1,48 @@ +{% 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>Kostenstellen</h4> + <form method="POST" style="border-width: 5px;"> + {% csrf_token %} + {% form form=form %} + {% endform %} + <button type="submit" class="waves-effect waves-light btn green"> + <i class="material-icons left">send</i> Kostenstelle anlegen + </button> + </form> + + <h4>Bestehende Kostenstellen</h4> + <div class="collection"> + {% 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"> + <form action="{% url 'costcenter_edit' costcenter.id %}" class="left"> + {% csrf_token %} + <input type="hidden" value="{{ costcenter.id }}" name="costcenter-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="{{ costcenter.id }}" name="costcenter-id"> + <button type="submit" onclick="return confirm('Wollen Sie die Kostenstelle 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/biscuit/apps/fibu/templates/fibu/index.html b/biscuit/apps/fibu/templates/fibu/index.html index 507d93e0c5e6f55fbfa66db3cbe156e65a0eb261..56aed0b4c1c330cee3530d05aff17d85e8d3a93e 100755 --- a/biscuit/apps/fibu/templates/fibu/index.html +++ b/biscuit/apps/fibu/templates/fibu/index.html @@ -21,31 +21,42 @@ <div class="collection"> {% for booking in bookings %} <div class="collection-item row"> - <span class="col s12 m9">{{ booking.description }}</span> + <span class="col s12 m8">{{ booking.description }}</span> <span class="col s12 m1 right-align">{{ booking.planned_amount }} €</span> <span class="col s12 m1 badge new center-align {{ booking.getStatus.style_class }}">{{ booking.getStatus.name }}</span> - <form action="{% url 'booking_edit' booking.id %}" class="col s12 m1 right-align"> - {% csrf_token %} - <input type="hidden" value="{{ booking.id }}" name="booking-id"> - {% if booking.status == 0 %} + <span class="col s12 m2 right-align"> + {% if booking.status == 0 %} + <form action="{% url 'booking_edit' booking.id %}" class="left"> + {% csrf_token %} + <input type="hidden" value="{{ booking.id }}" name="booking-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> - {% endif %} - </form> - <form action="" method="POST" class="col s12 m1"> + </form> + {% endif %} + {% if booking.status == 0 or booking.status == 1 %} + <form action="" method="POST" class="left"> + {% csrf_token %} + <input type="hidden" value="{{ booking.id }}" name="booking-id"> + <button type="submit" onclick="return confirm('Wollen Sie den Antrag 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> + {% endif %} + </span> + <form action="" method="POST" class="col s12 m1 left"> {% csrf_token %} <input type="hidden" value="{{ booking.id }}" name="booking-id"> <input type="hidden" value="{{ booking.status }}" name="booking-status"> {% if booking.status == 1 %} <button type="submit" name="ordered" - class="waves-effect waves-light btn-flat btn-flat-medium right-align" title="Status auf 'bestellt' ändern"> + class="waves-effect waves-light btn-flat btn-flat-medium left" title="Status auf 'bestellt' ändern"> <i class="material-icons center red-text">shopping_cart</i> </button> {% elif booking.status == 3 %} <button type="submit" name="submit-invoice" - class="waves-effect waves-light btn-flat btn-flat-medium right-align" title="Status auf 'Rechnung eingereicht' ändern"> + class="waves-effect waves-light btn-flat btn-flat-medium left" title="Status auf 'Rechnung eingereicht' ändern"> <i class="material-icons center red-text">description</i> </button> {% endif %} diff --git a/biscuit/apps/fibu/urls.py b/biscuit/apps/fibu/urls.py index 5e6809b7d74862054298905a2d9665f3c2d2fa86..faf15d86cb510177b68512fc766d31e5089f9a29 100755 --- a/biscuit/apps/fibu/urls.py +++ b/biscuit/apps/fibu/urls.py @@ -5,8 +5,7 @@ from . import views urlpatterns = [ path('', views.index, name='fibu_index'), path('check', views.check, name='booking_check'), - path('check', views.check, name='booking_check1'), - path('check', views.check, name='booking_check2'), + path('costcenter', views.costcenter, name='costcenter'), path('edit/<int:id>', views.edit, name='booking_edit'), # path('make_booking', views.make_booking, name='fibu_make_booking'), # path('edit/<int:id>', views.edit, name='booking_edit'), diff --git a/biscuit/apps/fibu/views.py b/biscuit/apps/fibu/views.py index 3fd45f31267d4d28a707a42e15ffab6da4898f0d..a5a11fc6b20d547980170dcc65701a1263626443 100644 --- a/biscuit/apps/fibu/views.py +++ b/biscuit/apps/fibu/views.py @@ -1,20 +1,28 @@ 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 +from .models import Booking, Costcenter from .filters import BookingFilter -from .forms import EditBookingForm +from .forms import EditBookingForm, EditCostcenterForm @login_required #@permission_required('fibu.view_booking') def index(request): - bookings = Booking.objects.filter() if request.method == 'POST': if 'booking-id' in request.POST: booking_id = request.POST['booking-id'] booking = Booking.objects.get(id=booking_id) - if 'ordered' in request.POST: + if 'cancel' in request.POST: + booking.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('fibu_index') + elif 'ordered' in request.POST: Booking.objects.filter(id=booking_id).update(status=3) return redirect('fibu_index') elif 'submit-invoice' in request.POST: @@ -27,10 +35,11 @@ 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(description=description, planned_amount=planned_amount, contact=request.user, justification=justification) + booking = Booking(account=account, description=description, planned_amount=planned_amount, contact=request.user, justification=justification) booking.save() # a = Activity(user=request.user, title="Antrag auf Unterrichtsbefreiung gestellt", @@ -40,6 +49,7 @@ def index(request): # a.save() # return redirect('fibu_make_booking') return redirect('fibu_index') + bookings = Booking.objects.filter() context = {'bookings': bookings, 'form': form} return render(request, 'fibu/index.html', context) @@ -94,8 +104,42 @@ def check(request): bookings = BookingFilter(request.GET, queryset=booking_list) return render(request, 'fibu/check.html', {'filter': bookings}) -def booking_check1(): - pass -def booking_check2(): - pass \ No newline at end of file +@login_required +#@permission_required('fibu.view_booking') +def costcenter(request): + if request.method == 'POST': + if 'costcenter-id' in request.POST: + costcenter_id = request.POST['costcenter-id'] + costcenter = Costcenter.objects.get(id=costcenter_id) + if 'cancel' in request.POST: + costcenter.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('costcenter') + print('Edit-Form erstellt ############# form.is_valid:', form.is_valid()) + form = EditCostcenterForm(instance=costcenter) + else: + form = EditCostcenterForm(request.POST or None) + else: + form = EditCostcenterForm() + if form.is_valid(): + name = form.cleaned_data['name'] + schoolyear = form.cleaned_data['schoolyear'] + costcenter = Costcenter(name=name, schoolyear=schoolyear) + costcenter.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('costcenter') + costcenter = Costcenter.objects.filter() + context = {'costcenter': costcenter, 'form': form} + return render(request, 'fibu/costcenter.html', context)