19 lines
769 B
Python
19 lines
769 B
Python
"""Utilitaires pour la numérotation des décisions du groupe."""
|
|
from sqlalchemy import func, select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.core.decision_types import PREFIXES_DECISION
|
|
from app.models.proposition import Proposition
|
|
|
|
|
|
async def prochain_numero_decision(groupe_id, type_decision: str, annee: int, db: AsyncSession) -> str:
|
|
prefixe = PREFIXES_DECISION.get(type_decision, "RES")
|
|
result = await db.execute(
|
|
select(func.count(Proposition.id)).where(
|
|
Proposition.groupe_id == groupe_id,
|
|
Proposition.numero_resolution.isnot(None),
|
|
Proposition.numero_resolution.like(f"{prefixe}-{annee}-%"),
|
|
)
|
|
)
|
|
count = result.scalar() or 0
|
|
return f"{prefixe}-{annee}-{count + 1:03d}"
|