frontend költség beállítások
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# /opt/docker/dev/service_finder/backend/app/services/analytics_service.py
|
||||
"""
|
||||
TCO (Total Cost of Ownership) Analytics Service.
|
||||
Számítások a vehicle.costs tábla alapján, árfolyam-átváltással a system_service segítségével.
|
||||
Számítások a fleet_finance.asset_costs tábla alapján, árfolyam-átváltással a system_service segítségével.
|
||||
"""
|
||||
|
||||
import logging
|
||||
@@ -10,7 +10,7 @@ from sqlalchemy import select, func, and_
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import selectinload
|
||||
|
||||
from app.models.vehicle import VehicleCost, CostCategory
|
||||
from app.models.fleet_finance import AssetCost, CostCategory
|
||||
from app.models import VehicleModelDefinition
|
||||
from app.models.marketplace.organization import Organization
|
||||
from app.services.system_service import SystemService
|
||||
@@ -56,22 +56,22 @@ class TCOAnalytics:
|
||||
"""
|
||||
# Alap lekérdezés: organization_id szűrés
|
||||
stmt = select(
|
||||
VehicleCost.amount,
|
||||
VehicleCost.currency,
|
||||
VehicleCost.category_id,
|
||||
AssetCost.amount_net,
|
||||
AssetCost.currency,
|
||||
AssetCost.category_id,
|
||||
CostCategory.code,
|
||||
CostCategory.name
|
||||
).join(
|
||||
CostCategory, VehicleCost.category_id == CostCategory.id
|
||||
CostCategory, AssetCost.category_id == CostCategory.id
|
||||
).where(
|
||||
VehicleCost.organization_id == organization_id
|
||||
AssetCost.organization_id == organization_id
|
||||
)
|
||||
|
||||
# Dátum szűrés
|
||||
if start_date:
|
||||
stmt = stmt.where(VehicleCost.date >= start_date)
|
||||
stmt = stmt.where(AssetCost.date >= start_date)
|
||||
if end_date:
|
||||
stmt = stmt.where(VehicleCost.date <= end_date)
|
||||
stmt = stmt.where(AssetCost.date <= end_date)
|
||||
|
||||
# Kategória szűrés
|
||||
if include_categories:
|
||||
@@ -87,7 +87,7 @@ class TCOAnalytics:
|
||||
category_totals = {}
|
||||
|
||||
for row in rows:
|
||||
amount = float(row.amount)
|
||||
amount = float(row.amount_net)
|
||||
source_currency = row.currency
|
||||
|
||||
# Átváltás célvalutára
|
||||
@@ -145,14 +145,14 @@ class TCOAnalytics:
|
||||
"""
|
||||
# Összes költség lekérdezése a járműhöz
|
||||
stmt = select(
|
||||
VehicleCost.amount,
|
||||
VehicleCost.currency,
|
||||
VehicleCost.organization_id,
|
||||
AssetCost.amount_net,
|
||||
AssetCost.currency,
|
||||
AssetCost.organization_id,
|
||||
Organization.name.label("org_name")
|
||||
).outerjoin(
|
||||
Organization, VehicleCost.organization_id == Organization.id
|
||||
Organization, AssetCost.organization_id == Organization.id
|
||||
).where(
|
||||
VehicleCost.vehicle_id == vehicle_model_id
|
||||
AssetCost.asset_id == vehicle_model_id
|
||||
)
|
||||
|
||||
result = await db.execute(stmt)
|
||||
@@ -166,7 +166,7 @@ class TCOAnalytics:
|
||||
owner_totals = {}
|
||||
|
||||
for row in rows:
|
||||
amount = float(row.amount)
|
||||
amount = float(row.amount_net)
|
||||
source_currency = row.currency
|
||||
|
||||
# Átváltás célvalutára
|
||||
@@ -238,23 +238,22 @@ class TCOAnalytics:
|
||||
"""
|
||||
# Alap lekérdezés: vehicle és cost összekapcsolása
|
||||
stmt = select(
|
||||
VehicleCost.amount,
|
||||
VehicleCost.currency,
|
||||
VehicleCost.vehicle_id,
|
||||
VehicleCost.odometer,
|
||||
AssetCost.amount_net,
|
||||
AssetCost.currency,
|
||||
AssetCost.asset_id,
|
||||
CostCategory.code,
|
||||
VehicleModelDefinition.make,
|
||||
VehicleModelDefinition.model,
|
||||
VehicleModelDefinition.fuel_type
|
||||
).join(
|
||||
VehicleModelDefinition, VehicleCost.vehicle_id == VehicleModelDefinition.id
|
||||
VehicleModelDefinition, AssetCost.asset_id == VehicleModelDefinition.id
|
||||
).join(
|
||||
CostCategory, VehicleCost.category_id == CostCategory.id
|
||||
CostCategory, AssetCost.category_id == CostCategory.id
|
||||
)
|
||||
|
||||
# Szűrés
|
||||
if vehicle_model_id:
|
||||
stmt = stmt.where(VehicleCost.vehicle_id == vehicle_model_id)
|
||||
stmt = stmt.where(AssetCost.asset_id == vehicle_model_id)
|
||||
benchmark_type = "specific_model"
|
||||
else:
|
||||
conditions = []
|
||||
@@ -295,7 +294,7 @@ class TCOAnalytics:
|
||||
category_counts = {}
|
||||
|
||||
for row in rows:
|
||||
amount = float(row.amount)
|
||||
amount = float(row.amount_net)
|
||||
source_currency = row.currency
|
||||
|
||||
# Átváltás
|
||||
@@ -304,11 +303,7 @@ class TCOAnalytics:
|
||||
)
|
||||
|
||||
total_cost_sum += converted_amount
|
||||
vehicle_ids.add(row.vehicle_id)
|
||||
|
||||
# Odometer összegzés (ha van)
|
||||
if row.odometer:
|
||||
total_odometer_sum += row.odometer
|
||||
vehicle_ids.add(row.asset_id)
|
||||
|
||||
# Kategória összesítés
|
||||
category_code = row.code
|
||||
@@ -322,11 +317,6 @@ class TCOAnalytics:
|
||||
vehicle_count = len(vehicle_ids)
|
||||
average_cost_per_vehicle = round(total_cost_sum / vehicle_count, 2)
|
||||
|
||||
# Kilométerenkénti átlag számítása
|
||||
average_cost_per_km = None
|
||||
if total_odometer_sum > 0:
|
||||
average_cost_per_km = round(total_cost_sum / total_odometer_sum, 4)
|
||||
|
||||
# Kategóriánkénti átlagok
|
||||
category_averages = {}
|
||||
for code, total in category_totals.items():
|
||||
@@ -342,7 +332,7 @@ class TCOAnalytics:
|
||||
"vehicle_count": vehicle_count,
|
||||
"total_cost_sum": round(total_cost_sum, 2),
|
||||
"average_cost_per_vehicle": average_cost_per_vehicle,
|
||||
"average_cost_per_km": average_cost_per_km,
|
||||
"average_cost_per_km": None,
|
||||
"by_category": category_averages,
|
||||
"currency": currency_target,
|
||||
"criteria": {
|
||||
|
||||
@@ -216,6 +216,19 @@ class AssetService:
|
||||
# Timeline
|
||||
'year_of_manufacture': asset_data.year_of_manufacture,
|
||||
'first_registration_date': asset_data.first_registration_date,
|
||||
|
||||
# Registration Documents
|
||||
'registration_certificate_number': asset_data.registration_certificate_number,
|
||||
'registration_certificate_validity': asset_data.registration_certificate_validity,
|
||||
'vehicle_registration_document_number': asset_data.vehicle_registration_document_number,
|
||||
|
||||
# Internationalization (ÚJ)
|
||||
'registration_country': asset_data.registration_country,
|
||||
'first_domestic_registration_date': asset_data.first_domestic_registration_date,
|
||||
'import_country': asset_data.import_country,
|
||||
'title_document_number': asset_data.title_document_number,
|
||||
'engine_number': asset_data.engine_number,
|
||||
'number_of_previous_owners': asset_data.number_of_previous_owners,
|
||||
}
|
||||
|
||||
# Remove None values from the dictionary
|
||||
|
||||
@@ -16,7 +16,7 @@ import logging
|
||||
from typing import Optional, List
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select
|
||||
from app.models.vehicle.vehicle import CostCategory
|
||||
from app.models.fleet_finance import CostCategory
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user