Files
tableau-de-bord/app/models.py
Antoine Van Elstraete 4c0093c2b0 feat: increase RTT from 18 to 19
- Update LeaveBalance model default rtt_total to 19
- Update all tests to verify 19 RTT instead of 18
- Update documentation (design and technical plan)
- Update run.py to bind to 0.0.0.0 for external access
- Update CLAUDE.md deployment instructions

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-13 13:45:19 +01:00

58 lines
2.3 KiB
Python

from app import db
from datetime import date, time, datetime
import sqlalchemy as sa
import sqlalchemy.orm as so
class WorkEntry(db.Model):
__tablename__ = "work_entries"
id: so.Mapped[int] = so.mapped_column(primary_key=True)
date: so.Mapped[date] = so.mapped_column(sa.Date, unique=True, nullable=False)
journey_profile_id: so.Mapped[str | None] = so.mapped_column(sa.String(64), nullable=True)
motor_vehicle_id: so.Mapped[str | None] = so.mapped_column(sa.String(64), nullable=True)
day_type: so.Mapped[str] = so.mapped_column(sa.String(16), nullable=False, default="WORK")
comment: so.Mapped[str | None] = so.mapped_column(sa.Text, nullable=True)
created_at: so.Mapped[datetime] = so.mapped_column(sa.DateTime, default=datetime.utcnow)
updated_at: so.Mapped[datetime] = so.mapped_column(
sa.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
)
time_slots: so.Mapped[list["TimeSlot"]] = so.relationship(
back_populates="entry", cascade="all, delete-orphan", order_by="TimeSlot.start_time"
)
def total_minutes(self) -> int:
total = 0
for slot in self.time_slots:
start = slot.start_time.hour * 60 + slot.start_time.minute
end = slot.end_time.hour * 60 + slot.end_time.minute
if end <= start:
end += 24 * 60
total += end - start
return total
def total_hours_str(self) -> str:
minutes = self.total_minutes()
return f"{minutes // 60}h{minutes % 60:02d}"
class TimeSlot(db.Model):
__tablename__ = "time_slots"
id: so.Mapped[int] = so.mapped_column(primary_key=True)
entry_id: so.Mapped[int] = so.mapped_column(sa.ForeignKey("work_entries.id"), nullable=False)
start_time: so.Mapped[time] = so.mapped_column(sa.Time, nullable=False)
end_time: so.Mapped[time] = so.mapped_column(sa.Time, nullable=False)
entry: so.Mapped["WorkEntry"] = so.relationship(back_populates="time_slots")
class LeaveBalance(db.Model):
__tablename__ = "leave_balance"
id: so.Mapped[int] = so.mapped_column(primary_key=True)
year: so.Mapped[int] = so.mapped_column(sa.Integer, unique=True, nullable=False)
conges_total: so.Mapped[int] = so.mapped_column(sa.Integer, default=28)
rtt_total: so.Mapped[int] = so.mapped_column(sa.Integer, default=19)