From 6076a9c8207a361841f3c6a2025e2805f98a59eb Mon Sep 17 00:00:00 2001 From: Christian Merten Date: Mon, 20 Mar 2023 21:11:06 +0100 Subject: [PATCH] finance: move some constants to settings, fix bug in overview --- jdav_web/finance/admin.py | 29 ++++++++++++++++------------- jdav_web/finance/models.py | 9 ++++----- jdav_web/jdav_web/settings.py | 5 +++++ 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/jdav_web/finance/admin.py b/jdav_web/finance/admin.py index 3decee5..9fcf5a1 100644 --- a/jdav_web/finance/admin.py +++ b/jdav_web/finance/admin.py @@ -6,6 +6,7 @@ from django.urls import path, reverse from functools import update_wrapper from django.utils.translation import gettext_lazy as _ from django.shortcuts import render +from django.conf import settings from .models import Ledger, Statement, Receipt, Transaction, Bill, StatementSubmitted, StatementConfirmed,\ StatementUnSubmitted @@ -205,21 +206,23 @@ class StatementSubmittedAdmin(admin.ModelAdmin): opts=self.opts, statement=statement, transaction_issues=statement.transaction_issues, - nights=statement.excursion.night_count, - price_per_night=statement.real_night_cost, - duration=statement.excursion.duration, - staff_count=statement.real_staff_count, - kilometers_traveled=statement.excursion.kilometers_traveled, - means_of_transport=statement.excursion.get_tour_approach(), - euro_per_km=statement.euro_per_km, - allowance_per_day=statement.ALLOWANCE_PER_DAY, total_bills=statement.total_bills, - nights_per_yl=statement.nights_per_yl, - allowance_per_yl=statement.allowance_per_yl, - transportation_per_yl=statement.transportation_per_yl, - total_per_yl=statement.total_per_yl, - total_staff=statement.total_staff, total=statement.total) + if statement.excursion is not None: + context = dict(context, + nights=statement.excursion.night_count, + price_per_night=statement.real_night_cost, + duration=statement.excursion.duration, + staff_count=statement.real_staff_count, + kilometers_traveled=statement.excursion.kilometers_traveled, + means_of_transport=statement.excursion.get_tour_approach(), + euro_per_km=statement.euro_per_km, + allowance_per_day=settings.ALLOWANCE_PER_DAY, + nights_per_yl=statement.nights_per_yl, + allowance_per_yl=statement.allowance_per_yl, + transportation_per_yl=statement.transportation_per_yl, + total_per_yl=statement.total_per_yl, + total_staff=statement.total_staff) return render(request, 'admin/overview_submitted_statement.html', context=context) diff --git a/jdav_web/finance/models.py b/jdav_web/finance/models.py index fc0284b..83cdc46 100644 --- a/jdav_web/finance/models.py +++ b/jdav_web/finance/models.py @@ -6,6 +6,7 @@ from django.utils import timezone from django.db import models from django.utils.translation import gettext_lazy as _ from members.models import Member, Freizeit, OEFFENTLICHE_ANREISE, MUSKELKRAFT_ANREISE +from django.conf import settings # Create your models here. @@ -37,8 +38,6 @@ class StatementManager(models.Manager): class Statement(models.Model): MISSING_LEDGER, NON_MATCHING_TRANSACTIONS, VALID = 0, 1, 2 - ALLOWANCE_PER_DAY = 10 - short_description = models.CharField(verbose_name=_('Short description'), max_length=30, blank=True) @@ -151,7 +150,7 @@ class Statement(models.Model): for bill in self.bill_set.all(): if not bill.costs_covered: continue - ref = "{}: {}".format(self.excursion.name, bill.short_description) + ref = "{}: {}".format(str(self), bill.short_description) Transaction(statement=self, member=bill.paid_by, amount=bill.amount, confirmed=False, reference=ref).save() # excursion specific @@ -216,7 +215,7 @@ class Statement(models.Model): if self.excursion is None: return 0 - return cvt_to_decimal(self.excursion.duration * self.ALLOWANCE_PER_DAY) + return cvt_to_decimal(self.excursion.duration * settings.ALLOWANCE_PER_DAY) @property def total_allowance(self): @@ -228,7 +227,7 @@ class Statement(models.Model): @property def real_night_cost(self): - return min(self.night_cost, 11) + return min(self.night_cost, settings.MAX_NIGHT_COST) @property def nights_per_yl(self): diff --git a/jdav_web/jdav_web/settings.py b/jdav_web/jdav_web/settings.py index 0f95769..a71263d 100644 --- a/jdav_web/jdav_web/settings.py +++ b/jdav_web/jdav_web/settings.py @@ -400,3 +400,8 @@ DEFAULT_SENDING_MAIL = os.environ.get('EMAIL_SENDING_ADDRESS', 'christian@localh # misc CONGRATULATE_MEMBERS_MAX = 10 + +# finance + +ALLOWANCE_PER_DAY = 10 +MAX_NIGHT_COST = 11