egyedi jármű szerkesztés előtti mentés

This commit is contained in:
Roo
2026-06-12 07:56:15 +00:00
parent 0a3fd8de74
commit ef8df9608c
29 changed files with 3863 additions and 396 deletions

View File

@@ -0,0 +1,70 @@
#!/usr/bin/env python3
"""
BodyTypeDictionary seed script.
Populates the vehicle.dict_body_types table with standardized body types.
Run inside the sf_api container:
docker compose exec sf_api python3 /app/backend/scripts/seed_body_types.py
"""
import asyncio
import sys
import os
# Ensure the backend directory is on the path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from app.database import AsyncSessionLocal, engine, Base
from app.models.vehicle.vehicle_definitions import BodyTypeDictionary
from sqlalchemy import text
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select
# ── Standardized Body Type Data ──
BODY_TYPES = [
# Personal (Személyautó)
{"vehicle_class": "personal", "code": "sedan", "name_hu": "Szedán"},
{"vehicle_class": "personal", "code": "hatchback", "name_hu": "Kompakt"},
{"vehicle_class": "personal", "code": "estate", "name_hu": "Kombi"},
{"vehicle_class": "personal", "code": "suv", "name_hu": "Városi Terepjáró"},
{"vehicle_class": "personal", "code": "coupe", "name_hu": "Kupé"},
{"vehicle_class": "personal", "code": "cabrio", "name_hu": "Kabrió"},
{"vehicle_class": "personal", "code": "mpv", "name_hu": "Egyterű"},
# Motorcycle (Motorkerékpár)
{"vehicle_class": "motorcycle", "code": "naked", "name_hu": "Naked Bike"},
{"vehicle_class": "motorcycle", "code": "sport", "name_hu": "Sport"},
{"vehicle_class": "motorcycle", "code": "touring", "name_hu": "Túra"},
{"vehicle_class": "motorcycle", "code": "enduro", "name_hu": "Enduró / Kaland"},
{"vehicle_class": "motorcycle", "code": "cruiser", "name_hu": "Cruiser"},
{"vehicle_class": "motorcycle", "code": "scooter", "name_hu": "Robogó"},
# Light Commercial (Kisteher)
{"vehicle_class": "light_commercial", "code": "van", "name_hu": "Furgon"},
{"vehicle_class": "light_commercial", "code": "pickup", "name_hu": "Pickup"},
{"vehicle_class": "light_commercial", "code": "chassis", "name_hu": "Alvázas"},
]
async def seed():
print("🌱 Seeding BodyTypeDictionary...")
async with AsyncSessionLocal() as session:
# Check if data already exists
result = await session.execute(select(BodyTypeDictionary).limit(1))
existing = result.scalar_one_or_none()
if existing:
print("⚠️ BodyTypeDictionary already has data. Skipping seed.")
return
for bt in BODY_TYPES:
entry = BodyTypeDictionary(
vehicle_class=bt["vehicle_class"],
code=bt["code"],
name_hu=bt["name_hu"],
)
session.add(entry)
await session.commit()
print(f"✅ Seeded {len(BODY_TYPES)} body types successfully!")
if __name__ == "__main__":
asyncio.run(seed())

View File

@@ -0,0 +1,93 @@
#!/usr/bin/env python3
"""
Seed script to update CostCategory visibility and accounting_code values.
Also drops the old 'cost_category' column from asset_costs table.
Usage: docker compose exec sf_api python3 /app/backend/scripts/seed_cost_category_visibility.py
"""
import asyncio
import logging
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker
from sqlalchemy import text
from app.core.config import settings
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Visibility rules:
# - FUEL, MAINTENANCE, SERVICE, TIRE, INSURANCE, PARKING, TOLL, OTHER -> 'both'
# - FINANCE, ADMIN -> 'b2b'
VISIBILITY_MAP = {
"FUEL": "both",
"MAINTENANCE": "both",
"SERVICE": "both",
"TIRE": "both",
"INSURANCE": "both",
"PARKING": "both",
"TOLL": "both",
"OTHER": "both",
"FINANCE": "b2b",
"ADMIN": "b2b",
}
async def main():
engine = create_async_engine(str(settings.SQLALCHEMY_DATABASE_URI))
async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
async with async_session() as session:
# 1. Update visibility for existing categories
logger.info("🔄 Updating visibility for existing cost categories...")
for code, visibility in VISIBILITY_MAP.items():
result = await session.execute(
text("""
UPDATE vehicle.cost_categories
SET visibility = :visibility
WHERE code = :code AND (visibility IS NULL OR visibility = 'both')
"""),
{"code": code, "visibility": visibility}
)
if result.rowcount > 0:
logger.info(f"{code} -> {visibility}")
# 2. Set default visibility for any categories without it
result = await session.execute(
text("""
UPDATE vehicle.cost_categories
SET visibility = 'both'
WHERE visibility IS NULL
""")
)
if result.rowcount > 0:
logger.info(f" ✅ Set default 'both' for {result.rowcount} categories")
# 3. Drop the old cost_category column from asset_costs
logger.info("🔄 Dropping old 'cost_category' column from asset_costs...")
# Check if the column still exists
check = await session.execute(
text("""
SELECT column_name FROM information_schema.columns
WHERE table_schema = 'vehicle'
AND table_name = 'asset_costs'
AND column_name = 'cost_category'
""")
)
if check.scalar():
await session.execute(
text("ALTER TABLE vehicle.asset_costs DROP COLUMN cost_category")
)
logger.info(" ✅ Dropped old 'cost_category' column from vehicle.asset_costs")
else:
logger.info(" ⏭️ Column 'cost_category' already removed")
await session.commit()
logger.info("✅ All updates completed successfully!")
await engine.dispose()
if __name__ == "__main__":
asyncio.run(main())