70 lines
2.7 KiB
Python
Executable File
70 lines
2.7 KiB
Python
Executable File
import enum
|
|
from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey, JSON
|
|
from sqlalchemy.dialects.postgresql import ENUM as PG_ENUM
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
from app.db.base import Base
|
|
|
|
class OrgType(str, enum.Enum):
|
|
# A tagok neveit kisbetűre állítjuk, hogy egyezzenek a Postgres Enum értékekkel
|
|
individual = "individual"
|
|
service = "service"
|
|
service_provider = "service_provider"
|
|
fleet_owner = "fleet_owner"
|
|
club = "club"
|
|
business = "business"
|
|
|
|
class Organization(Base):
|
|
__tablename__ = "organizations"
|
|
__table_args__ = {"schema": "data"}
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String, nullable=False)
|
|
|
|
# PG_ENUM használata a Python Enum-mal szinkronizálva
|
|
org_type = Column(
|
|
PG_ENUM(OrgType, name="orgtype", inherit_schema=True),
|
|
default=OrgType.individual
|
|
)
|
|
|
|
tax_number = Column(String(20), unique=True, index=True)
|
|
reg_number = Column(String(50))
|
|
headquarters_address = Column(String(255))
|
|
country_code = Column(String(2), default="HU")
|
|
|
|
status = Column(String(30), default="pending_verification")
|
|
is_deleted = Column(Boolean, default=False)
|
|
|
|
notification_settings = Column(JSON, default={
|
|
"notify_owner": True,
|
|
"notify_manager": True,
|
|
"notify_contact": True,
|
|
"alert_days_before": [30, 15, 7, 1]
|
|
})
|
|
external_integration_config = Column(JSON, default={})
|
|
|
|
owner_id = Column(Integer, ForeignKey("data.users.id"), nullable=True)
|
|
is_active = Column(Boolean, default=True)
|
|
is_transferable = Column(Boolean, default=True)
|
|
is_verified = Column(Boolean, default=False)
|
|
verification_expires_at = Column(DateTime(timezone=True), nullable=True)
|
|
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
assets = relationship("Asset", back_populates="organization", cascade="all, delete-orphan")
|
|
members = relationship("OrganizationMember", back_populates="organization")
|
|
owner = relationship("User", back_populates="owned_organizations")
|
|
|
|
class OrganizationMember(Base):
|
|
__tablename__ = "organization_members"
|
|
__table_args__ = {"schema": "data"}
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
organization_id = Column(Integer, ForeignKey("data.organizations.id"), nullable=False)
|
|
user_id = Column(Integer, ForeignKey("data.users.id"), nullable=False)
|
|
role = Column(String, default="driver")
|
|
|
|
organization = relationship("Organization", back_populates="members")
|
|
|
|
# Kompatibilitási réteg a korábbi kódokhoz
|
|
Organization.vehicles = Organization.assets |