44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
import uuid
|
|
|
|
from decimal import Decimal
|
|
from typing import TYPE_CHECKING, Optional
|
|
|
|
from sqlalchemy import Column, ForeignKey, Numeric
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.orm import Mapped, relationship
|
|
|
|
from .meta import Base
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
# if the target of the relationship is in another module
|
|
# that cannot normally be imported at runtime
|
|
from .journal import Journal
|
|
|
|
|
|
class Incentive(Base):
|
|
__tablename__ = "incentives"
|
|
id: uuid.UUID = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
voucher_id: uuid.UUID = Column("voucher_id", UUID(as_uuid=True), ForeignKey("vouchers.id"), nullable=False)
|
|
journal_id: uuid.UUID = Column("journal_id", UUID(as_uuid=True), ForeignKey("journals.id"), nullable=False)
|
|
days_worked: Decimal = Column("days_worked", Numeric(precision=5, scale=1), nullable=False)
|
|
points: Decimal = Column("points", Numeric(precision=5, scale=2), nullable=False)
|
|
|
|
journal: Mapped["Journal"] = relationship("Journal", back_populates="incentive")
|
|
|
|
def __init__(
|
|
self,
|
|
journal: "Journal",
|
|
days_worked: Decimal,
|
|
points: Decimal,
|
|
voucher_id: Optional[uuid.UUID] = None,
|
|
id_: Optional[uuid.UUID] = None,
|
|
) -> None:
|
|
self.journal = journal
|
|
self.days_worked = days_worked
|
|
self.points = points
|
|
if voucher_id is not None:
|
|
self.voucher_id = voucher_id
|
|
if id_ is not None:
|
|
self.id = id_
|