- apply_push now uses PRAGMA table_info() to get valid column names per
table and filters incoming data to only known columns, preventing
"no such column" SQLite errors from frontend-only fields like oracle_id
- Wrap each operation in try/except so one bad op doesn't abort the
whole batch; errors are returned in the conflicts list instead of 500
- Add server_default to all NOT NULL float/int columns so raw SQL
INSERT OR REPLACE without those fields still succeeds
- Align DB models with frontend schema.js:
- orders: add nr_comanda, client_nume, client_telefon, nr_auto,
marca_denumire, model_denumire, created_by
- order_lines: add norma_id, mecanic_id, ordine
- vehicles: add serie_sasiu, client_cod_fiscal (keep vin, client_cui
for REST API compat)
- catalog_*: rename nume → denumire to match frontend schema
- catalog_norme: align fields (cod, denumire, ore_normate)
- invoices: add serie_factura, modalitate_plata, client_cod_fiscal,
nr_auto, total_fara_tva, tva, total_general; keep total for compat
- appointments: add client_nume, client_telefon, data_ora, durata_minute,
status, order_id
- mecanici: add user_id, prenume, activ
- Fix seed.py to use denumire= instead of nome= after catalog rename
- Add 3 new sync push tests covering order insert with frontend fields,
unknown column filtering, and order_line with norma_id/mecanic_id/ordine
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
120 lines
2.4 KiB
Python
120 lines
2.4 KiB
Python
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, denumire=name)
|
|
)
|
|
counts["marci"] = len(MARCI)
|
|
|
|
# Ansamble
|
|
for name in ANSAMBLE:
|
|
db.add(
|
|
CatalogAnsamblu(id=uuid7(), tenant_id=tenant_id, denumire=name)
|
|
)
|
|
counts["ansamble"] = len(ANSAMBLE)
|
|
|
|
# Tipuri deviz
|
|
for name in TIPURI_DEVIZ:
|
|
db.add(
|
|
CatalogTipDeviz(id=uuid7(), tenant_id=tenant_id, denumire=name)
|
|
)
|
|
counts["tipuri_deviz"] = len(TIPURI_DEVIZ)
|
|
|
|
# Tipuri motoare
|
|
for name in TIPURI_MOTOARE:
|
|
db.add(
|
|
CatalogTipMotor(id=uuid7(), tenant_id=tenant_id, denumire=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
|