Cleanup: MB 2.0 Gap Analysis előtti állapot (adatok kizárva)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import uuid
|
||||
from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey, Numeric, text, Text, UniqueConstraint
|
||||
from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey, Numeric, text, Text, UniqueConstraint, BigInteger
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.dialects.postgresql import UUID as PG_UUID, JSONB
|
||||
from sqlalchemy.sql import func
|
||||
@@ -16,7 +16,6 @@ class AssetCatalog(Base):
|
||||
)
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
# Kapcsolat az MDM-hez
|
||||
master_definition_id = Column(Integer, ForeignKey("data.vehicle_model_definitions.id"), nullable=True)
|
||||
|
||||
make = Column(String, index=True, nullable=False)
|
||||
@@ -27,18 +26,15 @@ class AssetCatalog(Base):
|
||||
year_to = Column(Integer)
|
||||
vehicle_class = Column(String)
|
||||
fuel_type = Column(String, index=True)
|
||||
# ÚJ MEZŐ: Kapcsolat az MDM-hez
|
||||
|
||||
|
||||
master_definition = relationship("VehicleModelDefinition", back_populates="variants")
|
||||
# --- ÚJ OSZLOPOK (Ezeket add hozzá!) ---
|
||||
|
||||
power_kw = Column(Integer, index=True)
|
||||
engine_capacity = Column(Integer, index=True)
|
||||
max_weight_kg = Column(Integer)
|
||||
axle_count = Column(Integer)
|
||||
euro_class = Column(String(20))
|
||||
body_type = Column(String(100))
|
||||
# ---------------------------------------
|
||||
|
||||
engine_code = Column(String)
|
||||
factory_data = Column(JSONB, server_default=text("'{}'::jsonb"))
|
||||
@@ -56,18 +52,25 @@ class Asset(Base):
|
||||
current_organization_id = Column(Integer, ForeignKey("data.organizations.id"), nullable=True)
|
||||
catalog_id = Column(Integer, ForeignKey("data.vehicle_catalog.id"))
|
||||
|
||||
# Moderációs mezők a Robot 3 (OCR) számára
|
||||
is_verified = Column(Boolean, default=False)
|
||||
verification_method = Column(String(20)) # 'manual', 'ocr', 'vin_api'
|
||||
verification_notes = Column(Text, nullable=True) # Eltérések jegyzőkönyve
|
||||
catalog_match_score = Column(Numeric(5, 2), nullable=True) # 0-100% egyezési arány
|
||||
verification_method = Column(String(20))
|
||||
verification_notes = Column(Text, nullable=True)
|
||||
catalog_match_score = Column(Numeric(5, 2), nullable=True)
|
||||
|
||||
status = Column(String(20), default="active")
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
||||
|
||||
# --- KAPCSOLATOK (A kettőzött current_org törölve, pontosítva) ---
|
||||
catalog = relationship("AssetCatalog", back_populates="assets")
|
||||
current_org = relationship("Organization")
|
||||
|
||||
# 1. Jelenlegi szervezet (Üzemeltető telephely)
|
||||
current_org = relationship(
|
||||
"Organization",
|
||||
primaryjoin="Asset.current_organization_id == Organization.id",
|
||||
foreign_keys="[Asset.current_organization_id]"
|
||||
)
|
||||
|
||||
financials = relationship("AssetFinancials", back_populates="asset", uselist=False)
|
||||
telemetry = relationship("AssetTelemetry", back_populates="asset", uselist=False)
|
||||
assignments = relationship("AssetAssignment", back_populates="asset")
|
||||
@@ -76,6 +79,43 @@ class Asset(Base):
|
||||
reviews = relationship("AssetReview", back_populates="asset")
|
||||
ownership_history = relationship("VehicleOwnership", back_populates="vehicle")
|
||||
|
||||
registration_uuid = Column(PG_UUID(as_uuid=True), default=uuid.uuid4, index=True, nullable=False)
|
||||
is_corporate = Column(Boolean, default=False, server_default=text("false"))
|
||||
|
||||
# Tulajdonos és Üzembentartó oszlopok
|
||||
owner_person_id = Column(BigInteger, ForeignKey("data.persons.id"), nullable=True)
|
||||
owner_org_id = Column(Integer, ForeignKey("data.organizations.id"), nullable=True)
|
||||
operator_person_id = Column(BigInteger, ForeignKey("data.persons.id"), nullable=True)
|
||||
operator_org_id = Column(Integer, ForeignKey("data.organizations.id"), nullable=True)
|
||||
|
||||
# 2. Tulajdonos szervezet (Kapcsolat pótolva)
|
||||
owner_org = relationship(
|
||||
"Organization",
|
||||
primaryjoin="Asset.owner_org_id == Organization.id",
|
||||
foreign_keys="[Asset.owner_org_id]"
|
||||
)
|
||||
|
||||
# 3. Üzembentartó szervezet
|
||||
operator_org = relationship(
|
||||
"Organization",
|
||||
primaryjoin="Asset.operator_org_id == Organization.id",
|
||||
foreign_keys="[Asset.operator_org_id]"
|
||||
)
|
||||
|
||||
# 4. Tulajdonos magánszemély
|
||||
owner_person = relationship(
|
||||
"Person",
|
||||
primaryjoin="Asset.owner_person_id == Person.id",
|
||||
foreign_keys="[Asset.owner_person_id]"
|
||||
)
|
||||
|
||||
# 5. Üzembentartó magánszemély
|
||||
operator_person = relationship(
|
||||
"Person",
|
||||
primaryjoin="Asset.operator_person_id == Person.id",
|
||||
foreign_keys="[Asset.operator_person_id]"
|
||||
)
|
||||
|
||||
class AssetFinancials(Base):
|
||||
__tablename__ = "asset_financials"
|
||||
__table_args__ = {"schema": "data"}
|
||||
@@ -117,17 +157,14 @@ class AssetAssignment(Base):
|
||||
id = Column(PG_UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
asset_id = Column(PG_UUID(as_uuid=True), ForeignKey("data.assets.id"), nullable=False)
|
||||
organization_id = Column(Integer, ForeignKey("data.organizations.id"), nullable=False)
|
||||
|
||||
# ÚJ: Telephelyi hozzárendelés
|
||||
branch_id = Column(PG_UUID(as_uuid=True), ForeignKey("data.branches.id"), nullable=True)
|
||||
|
||||
assigned_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
released_at = Column(DateTime(timezone=True), nullable=True)
|
||||
status = Column(String(30), default="active")
|
||||
|
||||
asset = relationship("Asset", back_populates="assignments")
|
||||
organization = relationship("Organization")
|
||||
branch = relationship("Branch") # Új kapcsolat
|
||||
branch = relationship("Branch")
|
||||
|
||||
class AssetEvent(Base):
|
||||
__tablename__ = "asset_events"
|
||||
@@ -138,6 +175,7 @@ class AssetEvent(Base):
|
||||
recorded_mileage = Column(Integer)
|
||||
data = Column(JSONB, server_default=text("'{}'::jsonb"))
|
||||
asset = relationship("Asset", back_populates="events")
|
||||
registration_uuid = Column(PG_UUID(as_uuid=True), index=True, nullable=True)
|
||||
|
||||
class AssetCost(Base):
|
||||
__tablename__ = "asset_costs"
|
||||
@@ -159,6 +197,7 @@ class AssetCost(Base):
|
||||
asset = relationship("Asset", back_populates="costs")
|
||||
organization = relationship("Organization")
|
||||
driver = relationship("User")
|
||||
registration_uuid = Column(PG_UUID(as_uuid=True), index=True, nullable=True)
|
||||
|
||||
class ExchangeRate(Base):
|
||||
__tablename__ = "exchange_rates"
|
||||
@@ -169,23 +208,17 @@ class ExchangeRate(Base):
|
||||
rate = Column(Numeric(18, 6), nullable=False)
|
||||
|
||||
class CatalogDiscovery(Base):
|
||||
"""
|
||||
Discovery tábla: Ide gyűjtjük a piaci 'neveket' (pl. Citroen C3).
|
||||
A Robot innen indulva keresi meg az összes létező technikai variánst.
|
||||
"""
|
||||
__tablename__ = "catalog_discovery"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
make = Column(String(100), nullable=False, index=True)
|
||||
model = Column(String(100), nullable=False, index=True)
|
||||
vehicle_class = Column(String(50), index=True) # car, motorcycle, truck, stb.
|
||||
source = Column(String(50)) # 'hasznaltauto', 'mobile.de'
|
||||
vehicle_class = Column(String(50), index=True)
|
||||
source = Column(String(50))
|
||||
status = Column(String(20), server_default=text("'pending'"), index=True)
|
||||
attempts = Column(Integer, default=0)
|
||||
last_attempt = Column(DateTime(timezone=True))
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
# EGYESÍTETT __table_args__
|
||||
__table_args__ = (
|
||||
UniqueConstraint('make', 'model', 'vehicle_class', name='_make_model_class_uc'),
|
||||
{"schema": "data"}
|
||||
|
||||
Reference in New Issue
Block a user