Skip to content
Snippets Groups Projects
Commit 28e16037 authored by Frank Poetzsch-Heffter's avatar Frank Poetzsch-Heffter
Browse files

view, template and calculation for final accounts

parent b4efe7d4
No related branches found
No related tags found
No related merge requests found
......@@ -42,9 +42,12 @@ class Costcenter(models.Model):
class Account(models.Model):
# Buchungskonten, z.B. Fachschaften, Sekretariat, Schulleiter, Kopieren, Tafelnutzung
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)
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)
saldo = models.DecimalField(max_digits=9, decimal_places=2, default=0.00)
rest = models.DecimalField(max_digits=9, decimal_places=2, default=0.00)
def __str__(self):
return "%s: %s" % (self.costcenter, self.name)
......
{% include 'partials/header.html' %}
{% load material_form %}
<main>
{% block content %}
<h4>Schlussrechnung</h4>
<div class="collection">
{% for costcenter, accounts in costcenter_accounts.items %}
<h5 class="collection-item">{{ costcenter }}</h5>
<div class="collection">
<div class="collection-item row">
<span class="col s4 m4 ">Buchungskonto</span>
<span class="col s2 m2 right-align">zugeteiltes Budget</span>
<span class="col s2 m2 right-align">bisherige Ausgaben</span>
<span class="col s2 m2 right-align">verfügbare Reste</span>
</div>
{% for account in accounts %}
<div class="collection-item row">
<span class="col s4 m4">{{ account.name }}</span>
<span class="col s2 m2 right-align">{{ account.budget }}</span>
<span class="col s2 m2 right-align">{{ account.saldo }}</span>
<span class="col s2 m2 right-align">{{ account.rest }}</span>
</div>
{% endfor %}
</div>
{% endfor %}
</div>
{% endblock %}
</main>
{% include 'partials/footer.html' %}
......@@ -12,6 +12,7 @@ urlpatterns = [
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('account/final', views.final_account, name='final_account'),
# path('make_booking', views.make_booking, name='fibu_make_booking'),
# path('edit/<int:id>', views.edit, name='booking_edit'),
]
from django.contrib.auth.decorators import login_required, permission_required
from django.db.models import Sum
from django.urls import reverse
from django.shortcuts import render, redirect, get_object_or_404
from .models import Booking, Costcenter, Account
......@@ -257,3 +258,25 @@ def account_edit(request, id):
context = {'form': form}
return render(request, template, context)
@login_required
#@permission_required('fibu.view_booking')
def final_account(request):
costcenterlist = Costcenter.objects.filter()
costcenter_accounts = {}
account_rests = {}
for costcenter in costcenterlist:
accounts = Account.objects.filter(costcenter=costcenter)
# update saldo
for account in accounts:
saldo = Booking.objects.filter(account=account).aggregate(Sum('amount'))
saldo = saldo['amount__sum']
rest = account.budget - saldo
try:
Account.objects.filter(id=account.id).update(saldo=saldo, rest=rest)
except:
Account.objects.filter(id=account.id).update(saldo=0, rest=0)
costcenter_accounts[costcenter.name] = list(Account.objects.filter(costcenter=costcenter))
context = {'costcenter_accounts': costcenter_accounts, 'account_rests': account_rests}
return render(request, 'fibu/account/final.html', context)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment