Source code for ferrosoft.apps.emiflow.models.tegos

#  Copyright (c) 2025 Ferrosoft GmbH. All rights reserved.
"""In-memory value objects used by the TEGOS waste-management ERP adapter.

These types are not Django models — they carry data parsed out of TEGOS
order documents while transport chains and freight items are being
constructed. They live next to the persistent models because they share
domain vocabulary (posting types, materials, weights).
"""
from dataclasses import dataclass
from enum import StrEnum

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


[docs] class PostingType(StrEnum): """TEGOS order posting direction (purchase vs. sales).""" PURCHASE = "Purchase" SALES = "Sales"
[docs] def to_transport_type(self) -> TransportChainType: """Map the posting type to the corresponding emiflow transport-chain type. Returns: TransportChainType: ``INCOMING`` for ``PURCHASE``, ``OUTGOING`` for ``SALES``. Raises: ValueError: If a new ``PostingType`` member has been added without an explicit mapping. """ match self: case self.PURCHASE: return TransportChainType.INCOMING case self.SALES: return TransportChainType.OUTGOING case _: raise ValueError("Unknown posting type")
[docs] @dataclass class OrderLineGroup: """A batch of TEGOS order lines grouped by posting type and material.""" posting_type: PostingType material_reference: str lines: list[dict]
[docs] @dataclass class FreightItemGroup: """A weight + material pair aggregated from TEGOS order lines.""" weight: DecimalWithUnit material_name: str