summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2014-01-13 23:14:18 +0100
committerRené 'Necoro' Neumann <necoro@necoro.net>2014-01-13 23:14:18 +0100
commitb342dfd7d37c71392fa2d82e186562d1af236aef (patch)
tree0fa122d5e8b74488141e9e775b9910dc9411304d
parent2bbf3bf2d37b319f06bc9e3a1c6d9097aa287bfa (diff)
downloadkosten-b342dfd7d37c71392fa2d82e186562d1af236aef.tar.gz
kosten-b342dfd7d37c71392fa2d82e186562d1af236aef.tar.bz2
kosten-b342dfd7d37c71392fa2d82e186562d1af236aef.zip
Fix calculation of default time span for constant costs.
-rw-r--r--app/views/consts.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/views/consts.py b/app/views/consts.py
index 4b5ea68..c8d9d99 100644
--- a/app/views/consts.py
+++ b/app/views/consts.py
@@ -13,6 +13,14 @@ from functools import partial
mod = Blueprint('consts', __name__)
assert_authorisation = partial(assert_authorisation, ConstExpense.get)
+def one_year(d):
+ """Returns the date d', such that [d, d'] spans exactly one year.
+ In effect, this is d + 11 months (NB: not 12!)"""
+ if d.month == 1:
+ return d.replace(month = 12)
+ else:
+ return d.replace(month = (d.month + 11) % 12, year = d.year + 1)
+
#
# Form
#
@@ -23,7 +31,7 @@ class ConstForm(F.Form):
end = F.DateField(u'Ende', F.req,
format='%m.%Y',
- default=lambda: today().replace(year = today().year + 1),
+ default=lambda: one_year(today()),
description=u'(einschließlich)')
months = F.IntegerField(u'Zahlungsrythmus', F.req,
@@ -155,7 +163,7 @@ def add_from(other):
# replace some fields to be more meaningful
start = max(form.end.data, today())
form.start.data = start
- form.end.data = start.replace(year = start.year + 1)
+ form.end.data = one_year(start)
if not other.next: form.prev.data = other
return { 'form': form }