2026.03.30 front és garázs logika
This commit is contained in:
146
backend/app/scripts/create_test_vehicles.py
Normal file
146
backend/app/scripts/create_test_vehicles.py
Normal file
@@ -0,0 +1,146 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Teszt járművek létrehozása a teszt felhasználóhoz.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import uuid
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
sys.path.insert(0, '/app')
|
||||
|
||||
from app.db.session import AsyncSessionLocal
|
||||
from app.models.identity import User
|
||||
from app.models.marketplace.organization import Organization, OrganizationMember
|
||||
from app.models.vehicle.asset import Asset
|
||||
from app.models.vehicle.vehicle_definitions import VehicleModelDefinition
|
||||
|
||||
async def main():
|
||||
print("=" * 60)
|
||||
print("TESZT JÁRMŰVEK LÉTREHOZÁSA")
|
||||
print("=" * 60)
|
||||
|
||||
async with AsyncSessionLocal() as db:
|
||||
# 1. Keressük meg a teszt felhasználót
|
||||
print("\n1. TESZT FELHASZNÁLÓ KERESÉSE...")
|
||||
stmt = select(User).where(User.email == "tester_pro@profibot.hu")
|
||||
result = await db.execute(stmt)
|
||||
test_user = result.scalar_one_or_none()
|
||||
|
||||
if not test_user:
|
||||
print("❌ HIBA: A teszt felhasználó nem található!")
|
||||
return
|
||||
|
||||
print(f" ✅ Teszt felhasználó: ID={test_user.id}")
|
||||
|
||||
# 2. Keressük meg a szervezetet
|
||||
print("\n2. SZERVEZET KERESÉSE...")
|
||||
org_stmt = (
|
||||
select(Organization)
|
||||
.join(OrganizationMember)
|
||||
.where(OrganizationMember.user_id == test_user.id)
|
||||
.where(Organization.is_deleted == False)
|
||||
.limit(1)
|
||||
)
|
||||
org_result = await db.execute(org_stmt)
|
||||
organization = org_result.scalar_one_or_none()
|
||||
|
||||
if not organization:
|
||||
print("❌ HIBA: Nincs szervezet a felhasználóhoz!")
|
||||
return
|
||||
|
||||
print(f" ✅ Szervezet: {organization.name} (ID: {organization.id})")
|
||||
|
||||
# 3. Keressünk néhány járműmodellt a katalógusból
|
||||
print("\n3. JÁRMŰMODELLEK KERESÉSE A KATALÓGUSBÓL...")
|
||||
catalog_stmt = select(VehicleModelDefinition).limit(10)
|
||||
catalog_result = await db.execute(catalog_stmt)
|
||||
catalog_models = catalog_result.scalars().all()
|
||||
|
||||
if not catalog_models:
|
||||
print("❌ HIBA: Nincsenek járműmodellek a katalógusban!")
|
||||
return
|
||||
|
||||
print(f" ✅ {len(catalog_models)} járműmodell található a katalógusban.")
|
||||
|
||||
# 4. Hozzunk létre teszt járműveket
|
||||
print("\n4. TESZT JÁRMŰVEK LÉTREHOZÁSA...")
|
||||
|
||||
test_vehicles = [
|
||||
# (név, rendszám, catalog_id, privát vagy céges)
|
||||
("Privát Audi", "ABC-123", catalog_models[0].id, True),
|
||||
("Privát BMW", "DEF-456", catalog_models[1].id, True),
|
||||
("Privát Mercedes", "GHI-789", catalog_models[2].id, True),
|
||||
("Céges Ford", "JKL-012", catalog_models[3].id, False),
|
||||
("Céges Toyota", "MNO-345", catalog_models[4].id, False),
|
||||
("Céges Volkswagen", "PQR-678", catalog_models[5].id, False),
|
||||
]
|
||||
|
||||
created_count = 0
|
||||
for name, license_plate, catalog_id, is_private in test_vehicles:
|
||||
# Ellenőrizzük, hogy már létezik-e ilyen rendszámú jármű
|
||||
existing_stmt = select(Asset).where(Asset.license_plate == license_plate)
|
||||
existing_result = await db.execute(existing_stmt)
|
||||
if existing_result.scalar_one_or_none():
|
||||
print(f" ⚠️ '{license_plate}' rendszámú jármű már létezik, kihagyva.")
|
||||
continue
|
||||
|
||||
# Új Asset létrehozása
|
||||
new_asset = Asset(
|
||||
catalog_id=catalog_id,
|
||||
license_plate=license_plate,
|
||||
name=name,
|
||||
owner_person_id=test_user.id,
|
||||
owner_org_id=None if is_private else organization.id,
|
||||
status="active",
|
||||
price=15000000 if is_private else 20000000, # 15-20 millió HUF
|
||||
currency="HUF",
|
||||
individual_equipment={},
|
||||
created_at=datetime.now()
|
||||
)
|
||||
|
||||
db.add(new_asset)
|
||||
created_count += 1
|
||||
|
||||
mode_text = "Privát" if is_private else "Céges"
|
||||
print(f" ✅ {mode_text} jármű létrehozva: {name} ({license_plate})")
|
||||
|
||||
await db.commit()
|
||||
|
||||
# 5. Végeredmény
|
||||
print("\n" + "=" * 60)
|
||||
print("VÉGEREDMÉNY:")
|
||||
print("=" * 60)
|
||||
|
||||
# Járművek számolása
|
||||
private_stmt = select(Asset).where(
|
||||
Asset.owner_person_id == test_user.id,
|
||||
Asset.owner_org_id.is_(None)
|
||||
)
|
||||
private_result = await db.execute(private_stmt)
|
||||
private_count = len(private_result.scalars().all())
|
||||
|
||||
corporate_stmt = select(Asset).where(
|
||||
Asset.owner_person_id == test_user.id,
|
||||
Asset.owner_org_id == organization.id
|
||||
)
|
||||
corporate_result = await db.execute(corporate_stmt)
|
||||
corporate_count = len(corporate_result.scalars().all())
|
||||
|
||||
print(f"\n📊 ÖSSZEFOGLALÓ:")
|
||||
print(f" • Felhasználó: {test_user.email}")
|
||||
print(f" • Szervezet: {organization.name}")
|
||||
print(f" • Új járművek létrehozva: {created_count}")
|
||||
print(f" • Összes privát jármű: {private_count} db")
|
||||
print(f" • Összes céges jármű: {corporate_count} db")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("KÉSZ! A teszt járművek létrehozva.")
|
||||
print("Most már tesztelhető a Garage UI switcher.")
|
||||
print("=" * 60)
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user