diff --git a/finance/app/routers/planning.py b/finance/app/routers/planning.py
index 882377a..0a4eac4 100644
--- a/finance/app/routers/planning.py
+++ b/finance/app/routers/planning.py
@@ -3,7 +3,7 @@ from decimal import Decimal
from typing import Literal
from fastapi import APIRouter, Depends, HTTPException
-from pydantic import BaseModel, ConfigDict, Field
+from pydantic import BaseModel, ConfigDict, Field, model_validator
from sqlalchemy import delete, select
from sqlalchemy.orm import Session
@@ -28,6 +28,13 @@ class RecurringIn(BaseModel):
end_date: date | None = None
category_id: int | None = None
+ @model_validator(mode="after")
+ def _ende_nicht_vor_start(self):
+ if (self.start_date is not None and self.end_date is not None
+ and self.end_date < self.start_date):
+ raise ValueError("Ende darf nicht vor Start liegen")
+ return self
+
class RecurringOut(RecurringIn):
model_config = ConfigDict(from_attributes=True)
@@ -90,6 +97,10 @@ def patch_recurring(item_id: int, data: RecurringPatch,
_check_category(session, fields["category_id"])
for key, value in fields.items():
setattr(item, key, value)
+ if (item.start_date is not None and item.end_date is not None
+ and item.end_date < item.start_date):
+ session.rollback()
+ raise HTTPException(422, "Ende darf nicht vor Start liegen")
session.commit()
session.refresh(item)
return RecurringOut.model_validate(item)
diff --git a/finance/app/templates/planning.html b/finance/app/templates/planning.html
index 526b803..e9273cd 100644
--- a/finance/app/templates/planning.html
+++ b/finance/app/templates/planning.html
@@ -7,7 +7,7 @@
Wiederkehrende Posten
- | Name | Betrag | Rhythmus | Fälligkeitstag | Kategorie | |
+ | Name | Betrag | Rhythmus | Fälligkeitstag | Start | Ende | Kategorie | |
{% for r in recurring %}
@@ -16,6 +16,8 @@
{{ r.amount|eur }} € |
{{ r.rhythm|de_label }} |
{{ r.due_day }} |
+ {{ r.start_date.strftime('%d.%m.%Y') if r.start_date else '–' }} |
+ {{ r.end_date.strftime('%d.%m.%Y') if r.end_date else '–' }} |
{{ category_names.get(r.category_id, '–') }} |
|
@@ -43,6 +45,8 @@
+
+