Upload modelli stock e contratti
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
from datetime import datetime, timezone
|
||||
from sqlalchemy import String, DateTime, Integer, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class Contract(Base):
|
||||
__tablename__ = "contracts"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
contract_number: Mapped[str] = mapped_column(String(50), nullable=False)
|
||||
year: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
company: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
area: Mapped[str | None] = mapped_column(String(100))
|
||||
plate: Mapped[str | None] = mapped_column(String(10))
|
||||
customer_name: Mapped[str | None] = mapped_column(String(200))
|
||||
import_batch: Mapped[str | None] = mapped_column(String(100))
|
||||
imported_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
|
||||
)
|
||||
|
||||
valuation_contracts: Mapped[list["ValuationContract"]] = relationship(
|
||||
"ValuationContract", back_populates="contract"
|
||||
)
|
||||
|
||||
|
||||
class ValuationContract(Base):
|
||||
__tablename__ = "valuation_contracts"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
valuation_id: Mapped[int] = mapped_column(Integer, ForeignKey("valuations.id"), nullable=False)
|
||||
contract_id: Mapped[int] = mapped_column(Integer, ForeignKey("contracts.id"), nullable=False)
|
||||
linked_by: Mapped[int] = mapped_column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
linked_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
|
||||
)
|
||||
|
||||
valuation: Mapped["Valuation"] = relationship("Valuation", back_populates="contracts")
|
||||
contract: Mapped["Contract"] = relationship("Contract", back_populates="valuation_contracts")
|
||||
|
||||
|
||||
from app.models.valuation import Valuation
|
||||
@@ -0,0 +1,50 @@
|
||||
from datetime import datetime, timezone
|
||||
from decimal import Decimal
|
||||
from sqlalchemy import String, DateTime, DECIMAL, Integer, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class VehicleStock(Base):
|
||||
__tablename__ = "vehicle_stock"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
plate: Mapped[str] = mapped_column(String(10), nullable=False, index=True)
|
||||
brand: Mapped[str | None] = mapped_column(String(50))
|
||||
model: Mapped[str | None] = mapped_column(String(100))
|
||||
version: Mapped[str | None] = mapped_column(String(200))
|
||||
registration_date: Mapped[str | None] = mapped_column(String(20))
|
||||
mileage: Mapped[int | None] = mapped_column(Integer)
|
||||
location: Mapped[str | None] = mapped_column(String(100))
|
||||
import_batch: Mapped[str | None] = mapped_column(String(100))
|
||||
imported_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
|
||||
)
|
||||
|
||||
|
||||
class RepairCostAvg(Base):
|
||||
__tablename__ = "repair_costs_avg"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
model: Mapped[str] = mapped_column(String(100), nullable=False, index=True)
|
||||
avg_cost: Mapped[Decimal | None] = mapped_column(DECIMAL(10, 2))
|
||||
import_batch: Mapped[str | None] = mapped_column(String(100))
|
||||
imported_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
|
||||
)
|
||||
|
||||
|
||||
class VehicleSalesAvg(Base):
|
||||
__tablename__ = "vehicle_sales_avg"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
model: Mapped[str] = mapped_column(String(100), nullable=False, index=True)
|
||||
avg_stock_days: Mapped[Decimal | None] = mapped_column(DECIMAL(6, 1))
|
||||
avg_repair_cost: Mapped[Decimal | None] = mapped_column(DECIMAL(10, 2))
|
||||
avg_margin_eur: Mapped[Decimal | None] = mapped_column(DECIMAL(10, 2))
|
||||
avg_margin_pct: Mapped[Decimal | None] = mapped_column(DECIMAL(5, 2))
|
||||
avg_sale_price: Mapped[Decimal | None] = mapped_column(DECIMAL(10, 2))
|
||||
import_batch: Mapped[str | None] = mapped_column(String(100))
|
||||
imported_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
|
||||
)
|
||||
Reference in New Issue
Block a user