55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
import uuid
|
|
|
|
from typing import TYPE_CHECKING, List, Optional
|
|
|
|
from sqlalchemy import Boolean, Column, Unicode
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from ..schemas.cost_centre import CostCentreLink
|
|
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 .account import AccountBase
|
|
from .journal import Journal
|
|
|
|
|
|
class CostCentre(Base):
|
|
__tablename__ = "cost_centres"
|
|
|
|
id: uuid.UUID = Column("id", UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
name: str = Column("name", Unicode(255), unique=True)
|
|
is_fixture: bool = Column("is_fixture", Boolean, nullable=False)
|
|
|
|
accounts: List["AccountBase"] = relationship("AccountBase", back_populates="cost_centre")
|
|
journals: List["Journal"] = relationship("Journal", back_populates="cost_centre")
|
|
|
|
@property
|
|
def __name__(self) -> str:
|
|
return self.name
|
|
|
|
def __init__(self, name: str, id_: Optional[uuid.UUID] = None, is_fixture: bool = False) -> None:
|
|
self.name = name
|
|
if id_ is not None:
|
|
self.id = id_
|
|
self.is_fixture = is_fixture
|
|
|
|
@classmethod
|
|
def cost_centre_purchase(cls) -> uuid.UUID:
|
|
return uuid.UUID("7b845f95-dfef-fa4a-897c-f0baf15284a3")
|
|
|
|
@classmethod
|
|
def cost_centre_kitchen(cls) -> uuid.UUID:
|
|
return uuid.UUID("b2d398ce-e3cc-c542-9feb-5d7783e899df")
|
|
|
|
@classmethod
|
|
def cost_centre_overall(cls) -> uuid.UUID:
|
|
return uuid.UUID("36f59436-522a-0746-ae94-e0f746bf6c0d")
|
|
|
|
@classmethod
|
|
def overall(cls) -> CostCentreLink:
|
|
return CostCentreLink(id=uuid.UUID("36f59436-522a-0746-ae94-e0f746bf6c0d"), name="Overall")
|