Source code for ferrosoft.apps.emiflow.services.vehicle

#  Copyright (c) 2025 Ferrosoft GmbH. All rights reserved.
"""Heuristic mapping from freight weight to a likely :class:`VehicleType`.

Used during bulk import when the source data does not specify the
vehicle type explicitly. The thresholds are hard-coded approximations
and will likely become tenant-configurable.
"""
from decimal import Decimal

from ferrosoft.apps.emiflow.models import VehicleType
from ferrosoft.apps.ferrobase.models.decimal import DecimalWithUnit


[docs] def detect_vehicle_type( weight: DecimalWithUnit, ) -> VehicleType: """Guess the vehicle type that would typically carry ``weight``. Returns :class:`~VehicleType.ROAD` for less than 30 t, :class:`~VehicleType.RAIL` for 30..60 t, and :class:`~VehicleType.INLAND_SHIPPING` above. Kilogram input is converted to metric tons before comparison. """ if weight.unit.symbol == "kg": weight = (weight / Decimal(1000)).with_unit("t") # These values are just assumptions and likely need to be made configurable. if weight < Decimal(30): return VehicleType.ROAD elif weight < Decimal(60): return VehicleType.RAIL else: return VehicleType.INLAND_SHIPPING