- Split mother's name in KYC (last/first) - Added mileage_unit and fuel_type to Assets - Expanded AssetCost for international VAT and original currency - Fixed SQLAlchemy IndexError in asset catalog lookup - Added exchange_rate and ratings tables to models
88 lines
3.7 KiB
Python
Executable File
88 lines
3.7 KiB
Python
Executable File
import enum
|
|
import uuid
|
|
from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey, JSON, text
|
|
from sqlalchemy.dialects.postgresql import ENUM as PG_ENUM
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
from app.db.base_class import Base
|
|
from sqlalchemy.dialects.postgresql import UUID as PG_UUID
|
|
|
|
class OrgType(str, enum.Enum):
|
|
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)
|
|
|
|
# ÚJ MEZŐ: Egységes címkezelés (GeoService hibrid)
|
|
address_id = Column(PG_UUID(as_uuid=True), ForeignKey("data.addresses.id"), nullable=True)
|
|
|
|
# --- NÉVKEZELÉS ---
|
|
full_name = Column(String, nullable=False) # Teljes hivatalos név
|
|
name = Column(String, nullable=False) # Rövidített cégnév
|
|
display_name = Column(String(50)) # Alkalmazáson belüli rövidítés
|
|
|
|
# --- ATOMIZÁLT CÍMKEZELÉS (Kompatibilitási réteg) ---
|
|
address_zip = Column(String(10))
|
|
address_city = Column(String(100))
|
|
address_street_name = Column(String(150))
|
|
address_street_type = Column(String(50))
|
|
address_house_number = Column(String(20))
|
|
address_hrsz = Column(String(50))
|
|
address_stairwell = Column(String(20))
|
|
address_floor = Column(String(20))
|
|
address_door = Column(String(20))
|
|
country_code = Column(String(2), default="HU")
|
|
|
|
# --- ÜZLETI ADATOK ---
|
|
tax_number = Column(String(20), unique=True, index=True)
|
|
reg_number = Column(String(50))
|
|
|
|
org_type = Column(
|
|
PG_ENUM(OrgType, name="orgtype", inherit_schema=True),
|
|
default=OrgType.individual
|
|
)
|
|
|
|
status = Column(String(30), default="pending_verification")
|
|
is_deleted = Column(Boolean, default=False)
|
|
|
|
notification_settings = Column(JSON, server_default=text("'{ \"notify_owner\": true, \"alert_days_before\": [30, 15, 7, 1] }'::jsonb"))
|
|
external_integration_config = Column(JSON, server_default=text("'{}'::jsonb"))
|
|
|
|
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())
|
|
|
|
# Kapcsolatok
|
|
assets = relationship("AssetAssignment", back_populates="organization", cascade="all, delete-orphan")
|
|
members = relationship("OrganizationMember", back_populates="organization", cascade="all, delete-orphan")
|
|
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") # owner, manager, driver, service_staff
|
|
|
|
# JAVÍTVA: Jogosultságok JSONB mezője (can_add_asset, etc.)
|
|
permissions = Column(JSON, server_default=text("'{}'::jsonb"))
|
|
|
|
organization = relationship("Organization", back_populates="members")
|
|
user = relationship("app.models.identity.User") # Visszamutató kapcsolat a felhasználóra
|
|
|
|
# Kompatibilitási réteg
|
|
Organization.vehicles = Organization.assets |