feat(backend): sync endpoints + all models + seed + order workflow
- All business models: Vehicle, Order, OrderLine, Invoice, Appointment, CatalogMarca/Model/Ansamblu/Norma/Pret/TipDeviz/TipMotor, Mecanic - Sync endpoints: GET /sync/full, GET /sync/changes?since=, POST /sync/push with tenant isolation and last-write-wins conflict resolution - Order CRUD with state machine: DRAFT -> VALIDAT -> FACTURAT Auto-recalculates totals (manopera + materiale) - Vehicle CRUD: list, create, get, update - Seed data: 24 marci, 11 ansamble, 6 tipuri deviz, 5 tipuri motoare, 3 preturi - Alembic migration for all business models - 13 passing tests (auth + sync + orders) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
119
backend/app/db/seed.py
Normal file
119
backend/app/db/seed.py
Normal file
@@ -0,0 +1,119 @@
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.db.base import uuid7
|
||||
from app.db.models.catalog import (
|
||||
CatalogAnsamblu,
|
||||
CatalogMarca,
|
||||
CatalogPret,
|
||||
CatalogTipDeviz,
|
||||
CatalogTipMotor,
|
||||
)
|
||||
|
||||
MARCI = [
|
||||
"Audi",
|
||||
"BMW",
|
||||
"Citroen",
|
||||
"Dacia",
|
||||
"Fiat",
|
||||
"Ford",
|
||||
"Honda",
|
||||
"Hyundai",
|
||||
"Kia",
|
||||
"Mazda",
|
||||
"Mercedes-Benz",
|
||||
"Mitsubishi",
|
||||
"Nissan",
|
||||
"Opel",
|
||||
"Peugeot",
|
||||
"Renault",
|
||||
"Seat",
|
||||
"Skoda",
|
||||
"Suzuki",
|
||||
"Toyota",
|
||||
"Volkswagen",
|
||||
"Volvo",
|
||||
"Alfa Romeo",
|
||||
"Jeep",
|
||||
]
|
||||
|
||||
ANSAMBLE = [
|
||||
"Motor",
|
||||
"Cutie de viteze",
|
||||
"Frane",
|
||||
"Directie",
|
||||
"Suspensie",
|
||||
"Climatizare",
|
||||
"Electrica",
|
||||
"Caroserie",
|
||||
"Esapament",
|
||||
"Transmisie",
|
||||
"Revizie",
|
||||
]
|
||||
|
||||
TIPURI_DEVIZ = [
|
||||
"Deviz reparatie",
|
||||
"Deviz revizie",
|
||||
"Deviz diagnosticare",
|
||||
"Deviz estimativ",
|
||||
"Deviz vulcanizare",
|
||||
"Deviz ITP",
|
||||
]
|
||||
|
||||
TIPURI_MOTOARE = ["Benzina", "Diesel", "Hibrid", "Electric", "GPL"]
|
||||
|
||||
PRETURI = [
|
||||
{"denumire": "Manopera standard", "pret": 150.0, "um": "ora"},
|
||||
{"denumire": "Revizie ulei + filtru", "pret": 250.0, "um": "buc"},
|
||||
{"denumire": "Diagnosticare", "pret": 100.0, "um": "buc"},
|
||||
]
|
||||
|
||||
|
||||
async def seed_catalog(db: AsyncSession, tenant_id: str) -> dict:
|
||||
now = datetime.now(UTC).isoformat()
|
||||
counts = {}
|
||||
|
||||
# Marci
|
||||
for name in MARCI:
|
||||
db.add(
|
||||
CatalogMarca(id=uuid7(), tenant_id=tenant_id, nume=name)
|
||||
)
|
||||
counts["marci"] = len(MARCI)
|
||||
|
||||
# Ansamble
|
||||
for name in ANSAMBLE:
|
||||
db.add(
|
||||
CatalogAnsamblu(id=uuid7(), tenant_id=tenant_id, nume=name)
|
||||
)
|
||||
counts["ansamble"] = len(ANSAMBLE)
|
||||
|
||||
# Tipuri deviz
|
||||
for name in TIPURI_DEVIZ:
|
||||
db.add(
|
||||
CatalogTipDeviz(id=uuid7(), tenant_id=tenant_id, nume=name)
|
||||
)
|
||||
counts["tipuri_deviz"] = len(TIPURI_DEVIZ)
|
||||
|
||||
# Tipuri motoare
|
||||
for name in TIPURI_MOTOARE:
|
||||
db.add(
|
||||
CatalogTipMotor(id=uuid7(), tenant_id=tenant_id, nume=name)
|
||||
)
|
||||
counts["tipuri_motoare"] = len(TIPURI_MOTOARE)
|
||||
|
||||
# Preturi
|
||||
for p in PRETURI:
|
||||
db.add(
|
||||
CatalogPret(
|
||||
id=uuid7(),
|
||||
tenant_id=tenant_id,
|
||||
denumire=p["denumire"],
|
||||
pret=p["pret"],
|
||||
um=p["um"],
|
||||
)
|
||||
)
|
||||
counts["preturi"] = len(PRETURI)
|
||||
|
||||
await db.commit()
|
||||
return counts
|
||||
Reference in New Issue
Block a user