fix(absences): Feiertage über Jahreswechsel korrekt aus working_days rausrechnen
Security Audit / Python Dependency Audit (push) Canceled after 0s
Security Audit / Node.js Dependency Audit (push) Canceled after 0s
Security Audit / Frontend Build (tsc + vite) (push) Canceled after 0s

_get_holiday_dates() fragte nur PublicHoliday für data.start_date.year ab.
Ein Antrag über den Jahreswechsel (z.B. 28.12.-01.01.) rechnete den
Neujahrsfeiertag im Folgejahr daher nicht heraus -> Mitarbeiter verlor
einen Urlaubstag, den er nicht verbraucht hat. Neuer year_to-Parameter
deckt den Jahres-Range ab, beide Aufrufstellen (create_absence,
update_absence) angepasst. Regressionstest ergänzt.

Gefunden während Coverage-Arbeit an absence_service.py/report_service.py.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Ahyx6D3r7G1EuAc42nezn
This commit is contained in:
2026-09-02 23:50:28 +02:00
co-authored by Claude Sonnet 5
parent dd044793c6
commit 548738c9ea
2 changed files with 51 additions and 11 deletions
+13 -5
View File
@@ -154,7 +154,7 @@ class AbsenceService:
# Arbeitstage berechnen
holidays = await self._get_holiday_dates(
current_user.company_id, data.start_date.year, db
current_user.company_id, data.start_date.year, db, year_to=data.end_date.year
)
working_days = self._calc_working_days(
data.start_date, data.end_date, holidays,
@@ -302,7 +302,9 @@ class AbsenceService:
absence.approved_by = None
# Arbeitstage neu berechnen
holiday_dates = await self._get_holiday_dates(current_user.company_id, absence.start_date.year, db)
holiday_dates = await self._get_holiday_dates(
current_user.company_id, absence.start_date.year, db, year_to=absence.end_date.year
)
absence.working_days = Decimal(str(
self._calc_working_days(absence.start_date, absence.end_date,
holiday_dates, absence.half_day_start, absence.half_day_end)
@@ -836,9 +838,14 @@ class AbsenceService:
ob.taken_hours = max(Decimal("0"), ob.taken_hours - hours_to_refund)
async def _get_holiday_dates(
self, company_id: UUID, year: int, db: AsyncSession
self, company_id: UUID, year: int, db: AsyncSession, year_to: int | None = None
) -> set[date]:
"""Feiertage für die Company-Country holen."""
"""Feiertage für die Company-Country holen.
`year_to` optional für Zeiträume über einen Jahreswechsel (z.B. 28.12.-02.01.)
ohne würde der Feiertag im Folgejahr (Neujahr) fälschlich nicht aus
working_days rausgerechnet.
"""
from app.models.company import Company
from sqlalchemy import or_
@@ -846,8 +853,9 @@ class AbsenceService:
country = company.country if company else "DE"
state = company.state if company else None
years = [year] if year_to is None or year_to == year else list(range(year, year_to + 1))
q = select(PublicHoliday.date).where(
PublicHoliday.year == year,
PublicHoliday.year.in_(years),
PublicHoliday.country == country,
)
if state: