Co-authored-by: OpenAI/GPT-5.6-Terra <vibecoder@antoineve.me> Co-authored-by: OpenAI/GPT-5.6-Luna <vibecoder@antoineve.me> Co-authored-by: MiniMax/MiniMax-M3 <vibecoder@antoineve.me> Co-authored-by: DeepSeek/DeepSeek-v4-Flash <vibecoder@antoineve.me>
43 lines
1022 B
Python
43 lines
1022 B
Python
from datetime import date
|
|
|
|
import sqlalchemy as sa
|
|
|
|
from app import db
|
|
from app.models import LeaveBalance, WorkEntry
|
|
|
|
|
|
def compute_leave_used(year: int) -> dict[str, int]:
|
|
start = date(year, 1, 1)
|
|
end = date(year, 12, 31)
|
|
|
|
conges = (
|
|
db.session.scalar(
|
|
sa.select(sa.func.count()).where(
|
|
WorkEntry.date.between(start, end),
|
|
WorkEntry.day_type == "CONGE",
|
|
)
|
|
)
|
|
or 0
|
|
)
|
|
|
|
rtt = (
|
|
db.session.scalar(
|
|
sa.select(sa.func.count()).where(
|
|
WorkEntry.date.between(start, end),
|
|
WorkEntry.day_type == "RTT",
|
|
)
|
|
)
|
|
or 0
|
|
)
|
|
|
|
return {"conges": conges, "rtt": rtt}
|
|
|
|
|
|
def get_or_create_balance(year: int) -> LeaveBalance:
|
|
balance = db.session.scalar(sa.select(LeaveBalance).where(LeaveBalance.year == year))
|
|
if balance is None:
|
|
balance = LeaveBalance(year=year)
|
|
db.session.add(balance)
|
|
db.session.commit()
|
|
return balance
|