Source code for pas.models.presidential_allowance

from __future__ import annotations

from onegov.core.orm import Base
from onegov.core.orm.mixins import TimestampMixin
from onegov.pas import _
from sqlalchemy import ForeignKey
from sqlalchemy import UniqueConstraint
from sqlalchemy.orm import mapped_column
from sqlalchemy.orm import relationship
from sqlalchemy.orm import Mapped
from uuid import uuid4
from uuid import UUID


from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from onegov.pas.models import PASParliamentarian
    from onegov.pas.models import SettlementRun


[docs] PRESIDENT_YEARLY_ALLOWANCE = 20_000
[docs] VICE_PRESIDENT_YEARLY_ALLOWANCE = 5_000
[docs] PRESIDENT_QUARTERLY = PRESIDENT_YEARLY_ALLOWANCE // 4 # 5000
[docs] VICE_PRESIDENT_QUARTERLY = VICE_PRESIDENT_YEARLY_ALLOWANCE // 4 # 1250
[docs] ALLOWANCE_ROLES: dict[str, str] = { 'president': _('President'), 'vice_president': _('Vice president'), }
# FiBu account for presidential allowances # (amtliche Missionen Kantonsratspräsidiums)
[docs] FIBU_KONTO_ALLOWANCE = '3000.30'
[docs] LOHNART_ALLOWANCE_NR = '2400'
[docs] LOHNART_ALLOWANCE_TEXT = 'Jahreszulage KR-Präsidium'
[docs] class PresidentialAllowance(Base, TimestampMixin): """Tracks quarterly presidential allowances (Jahreszulage) for the president and vice president of the Kantonsrat."""
[docs] __tablename__ = 'pas_presidential_allowances'
[docs] __table_args__ = (UniqueConstraint('year', 'quarter', 'role'),)
#: Internal ID
[docs] id: Mapped[UUID] = mapped_column(primary_key=True, default=uuid4)
#: The year
[docs] year: Mapped[int]
#: The quarter (1-4)
[docs] quarter: Mapped[int]
#: The role: 'president' or 'vice_president'
[docs] role: Mapped[str]
#: The amount in CHF (cents not needed, always whole francs)
[docs] amount: Mapped[int]
#: The id of the parliamentarian
[docs] parliamentarian_id: Mapped[UUID] = mapped_column( ForeignKey('par_parliamentarians.id'), )
#: The parliamentarian
[docs] parliamentarian: Mapped[PASParliamentarian] = relationship()
#: Optional link to the settlement run this belongs to
[docs] settlement_run_id: Mapped[UUID | None] = mapped_column( ForeignKey('pas_settlements.id'), nullable=True, )
#: The settlement run
[docs] settlement_run: Mapped[SettlementRun | None] = relationship()
@property
[docs] def role_label(self) -> str: return ALLOWANCE_ROLES.get(self.role, '')
[docs] def __repr__(self) -> str: return ( f'<PresidentialAllowance {self.year}' f' Q{self.quarter} {self.role} {self.amount}>' )