ferrosoft.apps.emiflow.models package

ORM models for the emiflow application.

The package is split into one module per bounded sub-domain:

  • booking — emission booking records and lifecycle categories (the immutable journal of calculated emissions).

  • catalog — reference data for emission factors, energy carriers, emitters, and the catalogs they belong to.

  • dataimport — staging tables for bulk transport import.

  • intensityEmissionIntensity shared by transport operations, treatment operations, and emitters.

  • operation — transport operations (the activity definition reused across chain elements).

  • reporting — report definitions and report templates.

  • settings — per-tenant emiflow and Business Central settings.

  • signals — post-save / post-delete hooks that keep cross-cutting state (allocation, intensity ownership) consistent.

  • tegos — adapters for inbound data from the TEGOS waste-management ERP.

  • transport — transport chains, their elements, and freight items.

  • treatment — treatments, treatment operations, and their input/output lines.

Star-imports below flatten the public names into the package namespace so callers can from ferrosoft.apps.emiflow.models import Treatment without knowing which sub-module a model lives in.

Submodules

ferrosoft.apps.emiflow.models.booking module

Emission booking records and lifecycle categories.

This module defines the immutable journal of calculated emissions:

  • EmissionBookingRecord — one row per (lifecycle category, emitting entity, material) triple. Fields are denormalised (material arrays, partner names) so reports can query a single table without joining live operational data.

  • LifecycleCategory — user-defined categories plus the four predefined ones (treatment, incoming/outgoing transport, drop shipment) enumerated in PredefinedLCC.

  • LCCValue — abstract base for manually entered per-category emission values that subclasses attach to transports or treatments.

The EmissionBookingRecordQuerySet exposes the aggregations used by the reporting pipeline (totals by entity, by material, by lifecycle category) — all keyed off the denormalised columns so they remain valid even after the originating operation has changed.

class ferrosoft.apps.emiflow.models.booking.EmissionBookingRecord(*args, **kwargs)[source]

Bases: UUIDModel

One booking entry: an emission figure tied to a lifecycle category and entity.

Records are wide-and-denormalised: material codes/names, partner names, and unit symbols are copied into the row so report aggregations stay valid even if the underlying operation is later edited or deleted. extra holds optional contextual data (transport/activity distance, intensity at booking time) used by detail views.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

property activity_distance: DecimalWithUnit

Activity distance recorded alongside this booking, when applicable.

booking_date

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

creation_time

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property emission_intensity_operation: DecimalWithUnit

Operation-only emission intensity that produced this booking.

property emission_intensity_total: DecimalWithUnit

Total emission intensity that produced this booking.

property emission_operation

Operation-only emission paired with the denormalised unit symbol.

emission_operation_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property emission_total

Total emission paired with the denormalised unit symbol.

emission_total_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

emission_unit_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

emission_unit_symbol

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

entity_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

entity_reference

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

extra

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_next_by_booking_date(*, field=<django.db.models.fields.DateField: booking_date>, is_next=True, **kwargs)
get_next_by_creation_time(*, field=<django.db.models.fields.DateTimeField: creation_time>, is_next=True, **kwargs)
get_previous_by_booking_date(*, field=<django.db.models.fields.DateField: booking_date>, is_next=False, **kwargs)
get_previous_by_creation_time(*, field=<django.db.models.fields.DateTimeField: creation_time>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

incoming_partner_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

incoming_partner_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

lifecycle_category

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

lifecycle_category_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

material_code

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

material_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

material_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

modification_time

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <ferrosoft.apps.emiflow.models.booking.EmissionBookingRecordManager object>
outgoing_partner_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

outgoing_partner_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

save(*args, **kwargs)[source]

Stamp modification_time and forward to the default save.

simulation

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property transport_distance: DecimalWithUnit

Transport distance recorded alongside this booking (transport records only).

property weight

Booking weight paired with the denormalised unit symbol.

weight_unit_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

weight_unit_symbol

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

weight_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.booking.EmissionBookingRecordManager(*args, **kwargs)[source]

Bases: Manager

Manager exposing aggregation, lookup, and upsert helpers.

static calculate_proportions(method, lifecycles)[source]

Scale lifecycle totals against the chosen authoritative leg’s weight.

Used by PCF reports when the customer wants the incoming or outgoing transport weight to drive the emissions allocation. Lifecycle rows with weights larger than the authoritative leg are scaled down so they share the same denominator; smaller weights are left untouched. Returns the input unchanged when method is DISABLED or no authoritative row is present.

Return type:

Iterable[LifecycleResult]

find_first(lifecycle_category, entity_id)[source]

Return the first booking record for the given category and entity.

get_queryset()[source]

Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.

Return type:

EmissionBookingRecordQuerySet

sum_emissions(lifecycle_category, entity_id)[source]

Aggregate the entity’s emissions in one lifecycle category.

Return type:

LifecycleSum

static sum_lifecycles(results)[source]

Sum a sequence of LifecycleResult rows into a single LifecycleSum.

Convenience over Python-side iteration for callers that already have the per-lifecycle rows in memory (e.g. PCF totals).

Return type:

LifecycleSum

upsert(records)[source]

Bulk insert-or-update booking records and bump the tenant tonnage counter.

(lifecycle_category, entity_id, material_id) is the conflict target; on conflict every denormalised field is refreshed. Simulation rows are excluded from the tonnage counter so dry runs don’t burn through a customer’s subscription quota.

Return type:

list[EmissionBookingRecord]

class ferrosoft.apps.emiflow.models.booking.EmissionBookingRecordQuerySet(*args, **kwargs)[source]

Bases: QuerySet

QuerySet that knows how to roll booking records up for reports.

Each aggregation method returns rows with emission_total, emission_operation, weight, and the two average_* columns annotated as DecimalWithUnit values, so reports can format them without re-attaching units in Python.

emission_total()[source]

Group rows by (lifecycle_category, entity_id) and aggregate emissions.

Return type:

Iterable[EmissionTotal]

filter_material_name(name)[source]

Restrict the queryset to rows whose material array contains name.

get_emission_aggregate_columns()[source]

Return Sum expressions for total, operation, and weight columns.

Exposed for callers that need to compose their own aggregations on top of the shared unit-aware output fields.

Return type:

dict

pcf_lifecycles(material_name)[source]

Group rows for one material by lifecycle category and aggregate.

Used by the PCF report, which is product-specific and therefore always scoped to a single material name.

Return type:

Iterable[LifecycleResult]

pcf_total()[source]

Group rows by material and aggregate emissions.

Materials are stored as a PostgreSQL array per booking record; unnest is applied so a row carrying multiple materials contributes to each one independently. Useful for product carbon footprint reporting — hence the name.

Return type:

Iterable[PCFTotal]

class ferrosoft.apps.emiflow.models.booking.EmissionTotal

Bases: TypedDict

average_operation: DecimalWithUnit
average_total: DecimalWithUnit
emission_operation: DecimalWithUnit
emission_total: DecimalWithUnit
entity_id: UUID
lifecycle_category: int
lifecycle_category_names: str
weight: DecimalWithUnit
class ferrosoft.apps.emiflow.models.booking.LCCValue(*args, **kwargs)[source]

Bases: UUIDModel

Abstract base for manually entered per-lifecycle emission contributions.

Concrete subclasses (TransportLCCValue, TreatmentLCCValue) add the foreign key to the owning entity. Only custom (non-predefined) categories are intended to be selected on the form.

class Meta[source]

Bases: object

abstract = False
verbose_name = 'Lifecycle Category Value'
verbose_name_plural = 'Lifecycle Category Values'
emission_unit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

emission_unit_id
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

lifecycle_category

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

lifecycle_category_id
objects
property operation_emission

Operation emission value paired with its unit.

operation_emission_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property total_emission

Total emission value paired with its unit.

total_emission_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.booking.LCCValueManager(*args, **kwargs)[source]

Bases: Manager

Manager that eagerly joins the category and emission unit.

get_ordered()[source]

Return values sorted by lifecycle-category name.

get_queryset()[source]

Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.

class ferrosoft.apps.emiflow.models.booking.LifecycleCategory(*args, **kwargs)[source]

Bases: Model

A named bucket that booking records are attributed to.

The primary key is intentionally a small integer (not a UUID) so the four PredefinedLCC enum values can be used as the canonical PKs for the system-provided categories.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

get_absolute_url()[source]
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <ferrosoft.apps.emiflow.models.booking.LifecycleCategoryManager object>
predefined

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.booking.LifecycleCategoryManager(*args, **kwargs)[source]

Bases: Manager

Manager that upserts lifecycle categories by primary key.

upsert(objects)[source]

Bulk insert-or-update categories using id as the conflict target.

upsert_predefined()[source]

Ensure the four PredefinedLCC categories exist with their canonical IDs.

class ferrosoft.apps.emiflow.models.booking.LifecycleResult

Bases: TypedDict

average_operation: DecimalWithUnit
average_total: DecimalWithUnit
emission_operation: DecimalWithUnit
emission_total: DecimalWithUnit
lifecycle_category: int
lifecycle_category_names: str
weight: DecimalWithUnit
class ferrosoft.apps.emiflow.models.booking.LifecycleSum(emission_total=<factory>, emission_operation=<factory>, weight=<factory>, average_total=<factory>, average_operation=<factory>)[source]

Bases: object

Running totals over one or more LifecycleResult rows.

average_operation: DecimalWithUnit
average_total: DecimalWithUnit
emission_operation: DecimalWithUnit
emission_total: DecimalWithUnit
weight: DecimalWithUnit
class ferrosoft.apps.emiflow.models.booking.PCFTotal

Bases: TypedDict

average_operation: DecimalWithUnit
average_total: DecimalWithUnit
emission_operation: DecimalWithUnit
emission_total: DecimalWithUnit
lifecycle_category_names: str
material: str
weight: DecimalWithUnit
class ferrosoft.apps.emiflow.models.booking.PredefinedLCC(*values)[source]

Bases: IntegerChoices

Predefined Lifecycle Categories.

These correspond to (not necessarily 1-1) to models found in Emiflow, for which emissions can be calculated.

DROP_SHIPMENT = 4
INCOMING_TRANSPORT = 2
OUTGOING_TRANSPORT = 3
TREATMENT = 1
classmethod value_from(source)[source]

Map an upstream enum value to its corresponding lifecycle category.

Currently supports TransportChainType; raises ValueError for any other input type so unmapped values fail loudly during booking.

ferrosoft.apps.emiflow.models.catalog module

Reference catalog: emitters, energy carriers, and their emission factors.

A EmissionsCatalog is a published bundle of emission data (e.g. the GLEC public extract) with copyright and licence information. Each catalog contains Emitter (vehicles or hub equipment), EnergyCarrier, and EmissionFactor. Models share the shape of the upstream emiflow.json JSON schema so updates can be imported in bulk.

ferrosoft.apps.emiflow.models.catalog.CatalogDecimalField(*args, **kwargs)[source]

Build a DecimalField sized for catalog values.

Allocates eight fractional digits (factors are small) and only four integer digits, since catalog quantities rarely exceed four digits before the decimal point.

class ferrosoft.apps.emiflow.models.catalog.DataSource(*values)[source]

Bases: IntegerChoices

Provenance of the figures in a catalog (primary measured vs. defaults).

DEFAULT_DATA = 3
PRIMARY_DATA = 1
SECONDARY_DATA = 2
class ferrosoft.apps.emiflow.models.catalog.EmissionCategory(*values)[source]

Bases: IntegerChoices

The two emission categories tracked per energy carrier.

Operation covers tailpipe / process emissions; Energy Provision covers upstream emissions from producing and distributing the energy carrier (well-to-tank).

ENERGY_PROVISION = 3
OPERATION = 2
class ferrosoft.apps.emiflow.models.catalog.EmissionFactor(*args, **kwargs)[source]

Bases: ReadOnlyMixin, UUIDModel

A per-unit emission factor for one EnergyCarrier.

Typically four factors are stored per carrier, formed by the Cartesian product of two units (gCO2e/MJ and kgCOe/kg) and the two EmissionCategory values. The read_only flag is True for factors imported from a published catalog (which must be copied before being changed) and False for user-defined factors, which can be edited in place.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

category

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

energy_carrier

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

energy_carrier_id
property factor: DecimalWithUnit

Factor value paired with its unit, as a DecimalWithUnit.

get_absolute_url()[source]
get_category_display(*, field=<django.db.models.fields.PositiveIntegerField: category>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <ferrosoft.apps.emiflow.models.catalog.EmissionFactorManager object>
read_only

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

unit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

unit_id
value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.catalog.EmissionFactorManager(*args, **kwargs)[source]

Bases: Manager

Manager that eagerly joins the energy carrier and unit.

get_queryset()[source]

Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.

class ferrosoft.apps.emiflow.models.catalog.EmissionsCatalog(*args, **kwargs)[source]

Bases: UUIDModel

A named bundle of emission-calculation reference data.

Catalogs group Emitter, EnergyCarrier, and EmissionFactor entries together with their licensing terms. The schema mirrors the published emiflow.json JSON schema so third-party catalogs can be imported directly.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

copyright

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

data_source

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

emitters

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

energy_carriers

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

get_absolute_url()[source]
get_data_source_display(*, field=<django.db.models.fields.PositiveIntegerField: data_source>)
classmethod get_ordered()[source]

Return all catalogs sorted alphabetically by name.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

license_text

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

license_uri

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
class ferrosoft.apps.emiflow.models.catalog.Emitter(*args, **kwargs)[source]

Bases: ReadOnlyMixin, UUIDModel

A vehicle or piece of hub equipment that emits greenhouse gases.

The epitype field discriminates between vehicles (with a further vehicle_type) and hub equipment (material handlers, processing units). Each emitter has a default EnergyCarrier and an optional cached EmissionIntensity. The read_only flag inherited from ReadOnlyMixin is set to True for rows imported from a published catalog (which must be copied before they can be modified) and left False for user-defined entries, which are editable in place.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

catalog

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

catalog_id
emission_intensity

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

emission_intensity_id
energy_carrier

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

energy_carrier_id
epitype

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_absolute_url()[source]
get_epitype_display(*, field=<django.db.models.fields.PositiveIntegerField: epitype>)
classmethod get_ordered(catalog=None)[source]

Return emitters sorted by (catalog, name), optionally filtered to one catalog.

get_vehicle_type_display(*, field=<django.db.models.fields.PositiveIntegerField: vehicle_type>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <ferrosoft.apps.emiflow.models.catalog.EmitterManager object>
read_only

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

treatmentoperation_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

vehicle_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.catalog.EmitterEpitype(*values)[source]

Bases: IntegerChoicesMixin, IntegerChoices

Top-level type of an Emitter.

Vehicles are differentiated further by VehicleType; the term epitype distinguishes this overarching axis from the vehicle sub-type.

MATERIAL_HANDLER = 3
PROCESSING_UNIT = 4
VEHICLE = 1
classmethod hub_equipment()[source]

Return the subset of epitypes that designate hub (non-vehicle) equipment.

Return type:

tuple[EmitterEpitype]

class ferrosoft.apps.emiflow.models.catalog.EmitterManager(*args, **kwargs)[source]

Bases: Manager

Manager that eagerly joins catalog, energy carrier, and intensity unit.

get_queryset()[source]

Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.

class ferrosoft.apps.emiflow.models.catalog.EnergyCarrier(*args, **kwargs)[source]

Bases: ReadOnlyMixin, UUIDModel

A substance or phenomenon (fuel, electricity, heat) that powers an emitter.

Holds physical attributes (lower heating value, density) needed to translate between mass, volume, and energy when a quantity is expressed in a non-mass unit. The read_only flag distinguishes carriers imported from a published catalog (True, copy-on-write) from user-defined entries (False, editable in place).

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

application

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

catalog

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

catalog_id
composition

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

density

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

emission_factors

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

get_absolute_url()[source]
classmethod get_ordered(catalog=None)[source]

Return energy carriers sorted by (catalog, name), optionally filtered to one catalog.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

lower_heating

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
read_only

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

treatmentoperation_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class ferrosoft.apps.emiflow.models.catalog.LoadCharacteristics(*values)[source]

Bases: IntegerChoices

Vehicle load categories used by some catalog lookups.

AVERAGE = 2
CONTAINER = 4
HEAVY = 3
LIGHT = 1
class ferrosoft.apps.emiflow.models.catalog.VehicleType(*values)[source]

Bases: IntegerChoicesMixin, IntegerChoices

Sub-type of a VEHICLE emitter, by operating environment.

INLAND_SHIPPING = 3
MARITIME_SHIPPING = 4
RAIL = 2
ROAD = 1

ferrosoft.apps.emiflow.models.dataimport module

Staging models for bulk transport-chain imports.

Rows here represent one input line that the ferrosoft.apps.emiflow.dataimport services then turn into real TransportChain records. SimpleImportLine and MultiLineImportLine differ in whether one row maps to a whole transport chain or to one element of a multi-hop chain; MultiLineBookingRecord tracks which chains a given import job produced so it can post (or roll back) emissions atomically.

class ferrosoft.apps.emiflow.models.dataimport.ImportLine(*args, **kwargs)[source]

Bases: UUIDModel

Abstract base for one row staged for transport-chain creation.

Captures everything required to build a single FreightItem on a TransportChain: routing (start/destination address), cargo (material and weight), and chain metadata (incoterms, vehicle type, partners).

class Meta[source]

Bases: object

abstract = False
booking_date

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

consignee

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

consignee_id
consignor

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

consignor_id
destination_address()[source]

Return the destination location as an Address value object.

Return type:

Address

destination_city

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

destination_country

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

destination_country_id
destination_house_no

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

destination_postal_code

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

destination_street

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_incoterms_display(*, field=<django.db.models.fields.CharField: incoterms>)
get_transport_type_display(*, field=<django.db.models.fields.PositiveIntegerField: transport_type>)
get_vehicle_type_display(*, field=<django.db.models.fields.PositiveIntegerField: vehicle_type>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

incoterms

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

material

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

material_id
reference

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

start_address()[source]

Return the start location as an Address value object.

Return type:

Address

start_city

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

start_country

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

start_country_id
start_house_no

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

start_postal_code

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

start_street

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

transport_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

vehicle_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property weight: DecimalWithUnit

Cargo weight paired with its unit.

weight_unit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

weight_unit_id
weight_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.dataimport.MultiLineBookingRecord(*args, **kwargs)[source]

Bases: UUIDModel

Tracks which transport chains a multi-line import job has produced.

Used to post emissions for all chains an import created, and to clear the bookkeeping rows once posting is complete.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

classmethod add_transport(transport, job_id)[source]

Record that transport was produced by job_id.

classmethod clear_transports(job_id)[source]

Drop the bookkeeping rows for job_id (usually after emissions are posted).

classmethod get_transports(job_id)[source]

Return the IDs of all transport chains produced by job_id.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

job

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

job_id
objects = <django.db.models.manager.Manager object>
transport

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

transport_id
class ferrosoft.apps.emiflow.models.dataimport.MultiLineImportLine(*args, **kwargs)[source]

Bases: ImportLine, UUIDModel

One import row = one transport-chain element (TCE) for a multi-hop chain.

Lines with the same reference build up the chain in position order. Multiple materials per position are supported; the unique constraint includes material so the same leg can carry several materials.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

booking_date

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

consignee

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

consignee_id
consignor

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

consignor_id
destination_city

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

destination_country

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

destination_country_id
destination_house_no

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

destination_postal_code

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

destination_street

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_incoterms_display(*, field=<django.db.models.fields.CharField: incoterms>)
get_transport_type_display(*, field=<django.db.models.fields.PositiveIntegerField: transport_type>)
get_vehicle_type_display(*, field=<django.db.models.fields.PositiveIntegerField: vehicle_type>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

incoterms

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

material

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

material_id
objects = <django.db.models.manager.Manager object>
position

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

reference

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

start_city

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

start_country

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

start_country_id
start_house_no

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

start_postal_code

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

start_street

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

transport_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

vehicle_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

weight_unit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

weight_unit_id
weight_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.dataimport.SimpleImportLine(*args, **kwargs)[source]

Bases: ImportLine, UUIDModel

One import row = one transport chain with a single route step and material movement.

Reference is unique per row, so re-importing the same reference updates the staged line in place.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

booking_date

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

consignee

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

consignee_id
consignor

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

consignor_id
destination_city

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

destination_country

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

destination_country_id
destination_house_no

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

destination_postal_code

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

destination_street

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_incoterms_display(*, field=<django.db.models.fields.CharField: incoterms>)
get_transport_type_display(*, field=<django.db.models.fields.PositiveIntegerField: transport_type>)
get_vehicle_type_display(*, field=<django.db.models.fields.PositiveIntegerField: vehicle_type>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

incoterms

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

material

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

material_id
objects = <django.db.models.manager.Manager object>
reference

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

start_city

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

start_country

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

start_country_id
start_house_no

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

start_postal_code

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

start_street

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

transport_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

vehicle_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

weight_unit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

weight_unit_id
weight_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

ferrosoft.apps.emiflow.models.intensity module

Emission intensity values shared across transport ops, treatment ops, and emitters.

An EmissionIntensity is the calculated gCO2e per tkm (or gCO2e per t for treatments) figure with all of the input variables it was computed from. The owner_type + owner_id pair forms a weak polymorphic reference so the same intensity row can belong to any of the three intensity-capable model classes; cleanup is handled by the post-delete signals in ferrosoft.apps.emiflow.models.signals.

class ferrosoft.apps.emiflow.models.intensity.EmissionIntensity(*args, **kwargs)[source]

Bases: ReadOnlyMixin, UUIDModel

Calculated emission intensity together with its input variables.

The row records both output intensities (operation and energy provision values plus their shared unit) and input variables (factors, quantity of fuel, mass of materials, optional distance) so the calculation is fully reproducible. The read_only flag is True for intensities derived from imported catalog data (which must be copied via copy_with_owner() before modification) and False for user-computed intensities, which remain editable in place.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

copy_with_owner(owner_type, owner_id)[source]

Create a copy of this intensity attributed to a new owner.

Distance is zeroed out for owners that are not distance-based (see IntensityCapableEntity.is_distance_based()).

Parameters:
Returns:

The newly persisted copy.

Return type:

EmissionIntensity

property distance: DecimalWithUnit

Activity distance used in the calculation (zero when not distance-based).

distance_unit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

distance_unit_id
distance_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

enable_distance

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property energy_provision_intensity: DecimalWithUnit

Energy-provision emission intensity as a DecimalWithUnit.

energy_provision_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

factor_energy_provision_value

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

factor_energy_provision_value_id
factor_operation_value

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

factor_operation_value_id
get_absolute_url()[source]
get_owner_type_display(*, field=<django.db.models.fields.IntegerField: owner_type>)
property grade: int

Grade total intensity on a 0..3 scale (higher is better).

Thresholds are centred around the GLEC public-extract average of 117 gCO2e/tkm: 0–80 → 3, 81–140 → 2, 141–200 → 1, above 200 → 0.

Returns:

Grade number from 0 (worst) to 3 (best).

Return type:

int

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property mass: DecimalWithUnit

Total mass of treated materials used in the calculation.

mass_unit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

mass_unit_id
mass_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <ferrosoft.apps.emiflow.models.intensity.EmissionIntensityManager object>
property operation_intensity: DecimalWithUnit

Operation emission intensity as a DecimalWithUnit.

operation_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property owner

Resolve and return the owning entity via the weak owner_type/owner_id pair.

Returns:

The owning TransportOperation, TreatmentOperation, or Emitter instance.

Raises:

ValueError – If owner_type is not a recognised IntensityCapableEntity value.

owner_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

owner_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property quantity: DecimalWithUnit

Fuel or electricity quantity used in the calculation.

quantity_unit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

quantity_unit_id
quantity_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

read_only

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

unit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

unit_id
update_foreign_key()[source]

Point the owner’s emission_intensity FK at this row.

The relation is duplicated (weak owner_id here plus a real FK on the owner) so list views can select_related it; this method keeps the FK side in sync after a new intensity is inserted.

Raises:

ValueError – If the resolved owner has no emission_intensity attribute.

class ferrosoft.apps.emiflow.models.intensity.EmissionIntensityManager(*args, **kwargs)[source]

Bases: Manager

Manager that prefetches units and the two emission factor relations.

delete_of_owner(owner_type, owner_id)[source]

Delete the intensity row(s) owned by (owner_type, owner_id).

Used by post-delete signal handlers to keep this weakly-referenced table in sync with its owning entities.

get_queryset()[source]

Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.

class ferrosoft.apps.emiflow.models.intensity.IntensityCapableEntity(*values)[source]

Bases: IntegerChoices

Enumerate model types for which emission intensity can be defined.

See owner_type and owner_id in EmissionIntensity.

EMITTER = 3
TRANSPORT_OPERATION = 1
TREATMENT_OPERATION = 2
is_distance_based()[source]

Return True when this owner type factors distance into the intensity.

Treatment operations don’t move freight, so their intensities are not divided by a distance term.

Return type:

bool

ferrosoft.apps.emiflow.models.operation module

Transport-operation model and its operation-type enum.

A TransportOperation is the activity definition (emitter + energy carrier + activity type) that is reused across one or more transport-chain elements. It owns an EmissionIntensity once calculated.

class ferrosoft.apps.emiflow.models.operation.OperationEpitype(*values)[source]

Bases: IntegerChoicesMixin, IntegerChoices

The standard defines two kinds of operations, transport and hub operation.

For our data model it is useful to combine them into one data type (OperationCategory) and differentiate between transport and hub operation by the “epitype”. This is an overarching type, because transport operations are further characterized by their own type.

HUB = 2
TRANSPORT = 1
class ferrosoft.apps.emiflow.models.operation.TransportOperation(*args, **kwargs)[source]

Bases: ReadOnlyMixin, UUIDModel

A reusable transport-or-hub activity definition.

Combines an Emitter and an EnergyCarrier with an activity type (transport vs. hub) and an optional cached EmissionIntensity. The read_only flag is True for operations derived from imported catalog data (which must be copied before modification) and False for user-defined operations, which remain editable in place.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

activity_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

emission_intensity

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

emission_intensity_id
emitter

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

emitter_id
energy_carrier

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

energy_carrier_id
get_absolute_url()[source]
get_activity_type_display(*, field=<django.db.models.fields.IntegerField: activity_type>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <ferrosoft.apps.emiflow.models.operation.TransportOperationManager object>
read_only

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

reference

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

transport_chain_elements

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class ferrosoft.apps.emiflow.models.operation.TransportOperationManager(*args, **kwargs)[source]

Bases: Manager

Default manager that eagerly joins the emitter, energy carrier, and intensity.

get_queryset()[source]

Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.

ferrosoft.apps.emiflow.models.reporting module

Models for emission reports and the templates that render them.

A Report captures the user’s selection (type, filter query string, proportional-emission method); a ReportTemplate captures the visual chrome (logo, preamble, epilogue) reused across generated documents. Logos are inlined as base64 so the rendered HTML can be turned into PDF by WeasyPrint without external fetches.

class ferrosoft.apps.emiflow.models.reporting.AspectRatio(*values)[source]

Bases: IntegerChoices

Preset width:height ratios available for logo sizing.

AUTOMATIC = 0
RATIO_16_10 = 2
RATIO_16_9 = 1
RATIO_1_1 = 3
RATIO_1_2 = 4
class ferrosoft.apps.emiflow.models.reporting.Base64Image(media_type, content)[source]

Bases: object

An image inlined as a base64 string for embedding in rendered HTML/PDF.

content: str

Image data encoded as base64.

classmethod from_stored_file(file)[source]

Read file and return its content base64-encoded.

Returns None when the underlying storage file is missing, which can happen if the storage backend has been cleared.

Return type:

Base64Image | None

media_type: str

Media/MIME type

class ferrosoft.apps.emiflow.models.reporting.PhotoOrientation(*values)[source]

Bases: IntegerChoices

Orientation of a logo image (landscape or portrait).

LANDSCAPE = 1
PORTRAIT = 2
class ferrosoft.apps.emiflow.models.reporting.ProportionalEmission(*values)[source]

Bases: IntegerChoices

Which transport leg’s weight overrides the others when computing PCF.

When enabled, the chosen leg’s weight is treated as authoritative and other lifecycle categories’ emissions are scaled down proportionally.

DISABLED = 0
INCOMING_TRANSPORT = 2
OUTGOING_TRANSPORT = 1
class ferrosoft.apps.emiflow.models.reporting.Report(*args, **kwargs)[source]

Bases: UUIDModel

A saved emission report (selection criteria plus presentation options).

Reports persist the filter query string they were generated from so the same set of booking records can be reproduced later through get_user_filtered().

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

creation_time

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

filters

Filter query string for use by FilterSet class

get_absolute_url()[source]
get_next_by_creation_time(*, field=<django.db.models.fields.DateTimeField: creation_time>, is_next=True, **kwargs)
get_previous_by_creation_time(*, field=<django.db.models.fields.DateTimeField: creation_time>, is_next=False, **kwargs)
get_proportional_emissions_display(*, field=<django.db.models.fields.IntegerField: proportional_emissions>)
get_type_display(*, field=<django.db.models.fields.IntegerField: type>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
proportional_emissions

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

reference

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.reporting.ReportTemplate(*args, **kwargs)[source]

Bases: UUIDModel

Reusable visual template applied when rendering a Report.

Carries the document title, preamble, epilogue, sender address, and a company logo (with explicit sizing/orientation hints because PDF renderers can’t infer them reliably).

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

company_logo_aspect_ratio

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property company_logo_base64: Base64Image | None[source]

Return the company logo as a Base64Image or None when unset.

company_logo_id
company_logo_orientation

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

property company_logo_style: str

Return an inline CSS style value sizing the company logo.

company_logo_width

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

document_epilogue

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

document_preamble

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

document_sender

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

document_sender_id
document_title

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_absolute_url()[source]
get_company_logo_aspect_ratio_display(*, field=<django.db.models.fields.IntegerField: company_logo_aspect_ratio>)
get_company_logo_orientation_display(*, field=<django.db.models.fields.IntegerField: company_logo_orientation>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
class ferrosoft.apps.emiflow.models.reporting.ReportType(*values)[source]

Bases: IntegerChoices

The supported report formats.

PCF = 1
TRANSPORT = 2
WAREHOUSE = 3

ferrosoft.apps.emiflow.models.settings module

Per-tenant emiflow configuration models.

Settings is a singleton (created lazily on first read) that holds references to storage directories and the user-defined emissions catalog; TransportChainDefaults keeps default transport-chain attributes per vehicle type; BusinessCentralSettings holds OAuth credentials for the Dynamics 365 Business Central integration.

class ferrosoft.apps.emiflow.models.settings.BusinessCentralSettings(*args, **kwargs)[source]

Bases: UUIDModel

Microsoft Dynamics 365 Business Central connection settings (per tenant).

Stores the BC tenant ID, environment, API base URL, and OAuth client-credentials parameters used by the BC integration in ferrosoft.apps.emiflow.services.businesscentral.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

api_base_url

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

environment

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_absolute_url()[source]
classmethod get_instance()[source]

Return the singleton BC settings row, creating it on first call.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

oauth_auth_url

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

oauth_client_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

oauth_client_secret

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

oauth_scope

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
tenant_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.settings.Settings(*args, **kwargs)[source]

Bases: UUIDModel

User configurable settings for Emiflow.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

company_logo_directory

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

company_logo_directory_id
get_company_logo_directory()[source]

Resolve the company-logo directory, creating it on first call.

Falls back to creating (or fetching) a directory named Company Logos and persisting the FK when the field was unset.

Return type:

Directory

classmethod get_instance()[source]

Return the singleton Settings row, creating it on first call.

Prefetches the related TransportChainDefaults rows so subsequent get_transport_chain_defaults lookups don’t hit the database.

Return type:

Settings

get_transport_chain_defaults(vehicle_type)[source]

Return the defaults row for vehicle_type, inserting an empty one if absent.

Return type:

TransportChainDefaults

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
report_directory

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

report_directory_id
transport_chain_defaults

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

user_catalog

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

user_catalog_id
class ferrosoft.apps.emiflow.models.settings.TransportChainDefaults(*args, **kwargs)[source]

Bases: UUIDModel

Per-vehicle-type defaults applied when creating a new transport chain.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

property are_defaults_set: bool

Return True when at least a distance type has been configured.

distance_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_distance_type_display(*, field=<django.db.models.fields.PositiveIntegerField: distance_type>)
get_vehicle_type_display(*, field=<django.db.models.fields.PositiveIntegerField: vehicle_type>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
settings

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

settings_id
transport_operation

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

transport_operation_id
vehicle_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

ferrosoft.apps.emiflow.models.signals module

Cross-model lifecycle hooks for emiflow.

Two concerns are wired up here:

  • Whenever a treatment-operation output line is inserted or removed, the parent operation’s allocation is recomputed (no-op under manual allocation).

  • Whenever an entity that owns an EmissionIntensity (transport operation, treatment operation, or emitter) is deleted, the matching intensity row is removed. The intensity table uses a weak (owner_type, owner_id) reference rather than a real foreign key, so this cascade must be driven explicitly from signals.

The module is loaded via the wildcard import in ferrosoft.apps.emiflow.models.__init__, which is what registers these receivers at app startup.

ferrosoft.apps.emiflow.models.signals.allocate_treatment_emissions_after_deletion(instance, **kwargs)[source]

Recompute parent operation’s allocation after an output line is deleted.

ferrosoft.apps.emiflow.models.signals.allocate_treatment_emissions_after_insertion(instance, **kwargs)[source]

Recompute parent operation’s allocation after an output line is saved.

ferrosoft.apps.emiflow.models.signals.delete_emitter_emission_intensity(instance, **kwargs)[source]

Remove the EmissionIntensity owned by a deleted emitter.

ferrosoft.apps.emiflow.models.signals.delete_transport_operation_emission_intensity(instance, **kwargs)[source]

Remove the EmissionIntensity owned by a deleted transport operation.

ferrosoft.apps.emiflow.models.signals.delete_treatment_operation_emission_intensity(instance, **kwargs)[source]

Remove the EmissionIntensity owned by a deleted treatment operation.

ferrosoft.apps.emiflow.models.tegos module

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).

class ferrosoft.apps.emiflow.models.tegos.FreightItemGroup(weight, material_name)[source]

Bases: object

A weight + material pair aggregated from TEGOS order lines.

material_name: str
weight: DecimalWithUnit
class ferrosoft.apps.emiflow.models.tegos.OrderLineGroup(posting_type, material_reference, lines)[source]

Bases: object

A batch of TEGOS order lines grouped by posting type and material.

lines: list[dict]
material_reference: str
posting_type: PostingType
class ferrosoft.apps.emiflow.models.tegos.PostingType(*values)[source]

Bases: StrEnum

TEGOS order posting direction (purchase vs. sales).

PURCHASE = 'Purchase'
SALES = 'Sales'
to_transport_type()[source]

Map the posting type to the corresponding emiflow transport-chain type.

Returns:

INCOMING for PURCHASE, OUTGOING for SALES.

Return type:

TransportChainType

Raises:

ValueError – If a new PostingType member has been added without an explicit mapping.

ferrosoft.apps.emiflow.models.transport module

Transport-chain domain models.

A TransportChain is one consignment from consignor to consignee broken into ordered TransportChainElement (TCE) hops. Each TCE points at a reusable TransportOperation (the activity definition) and may carry geo-points for shortest-feasible or great- circle distance calculations. The chain’s freight is described by FreightItem rows (material + weight). Custom per-lifecycle emissions are attached via TransportLCCValue.

class ferrosoft.apps.emiflow.models.transport.ActivityDistanceParameters(distance_type, distance, daf, origin, destination)[source]

Bases: object

Includes activity distance along with some related parameters.

Note that “activity distance” only has meaning for TCE’s of epitype TRANSPORT. For those, activity distance is transport activity.

For HUB TCE’s on the other hand, no activity distance exists. Freight item mass is the transport activity in this case.

daf

Distance Adjustment Factor

daf: Decimal
destination: TCEGeoDestination | None
distance: DecimalWithUnit
distance_type: DistanceType
origin: TCEGeoOrigin | None
exception ferrosoft.apps.emiflow.models.transport.BookingError[source]

Bases: RuntimeError

BookingError is raised by TransportChain.book.

Its message is translated and should be shown to the user.

class ferrosoft.apps.emiflow.models.transport.BookingStatus(*values)[source]

Bases: IntegerChoices

Lifecycle state of a TransportChain.

Posted chains are immutable to keep the booking journal consistent.

OPEN = 1
POSTED = 2
class ferrosoft.apps.emiflow.models.transport.DistanceType(*values)[source]

Bases: IntegerChoicesMixin, IntegerChoices

How the activity distance for a TCE is determined.

ACTUAL_DISTANCE = 1
GREAT_CIRCLE = 3
SHORTEST_FEASIBLE = 2
class ferrosoft.apps.emiflow.models.transport.FreightItem(*args, **kwargs)[source]

Bases: UUIDModel

Quantified material allocated to a transport chain.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

chain

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

chain_id
get_absolute_url()[source]
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

material

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

material_id
objects = <ferrosoft.apps.emiflow.models.transport.FreightItemManager object>
property weight

Freight item’s weight paired with its unit.

weight_unit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

weight_unit_id
weight_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.transport.FreightItemManager(*args, **kwargs)[source]

Bases: Manager

Manager with upsert and weight-aggregation helpers.

sum_weight(chain_id)[source]

Return the total freight weight for chain_id, normalised to metric tons.

Weights are summed per unit at the database layer and then unit-converted in Python so chains carrying a mix of units (e.g. kg + t) produce a single, meaningful total.

upsert(records)[source]

Bulk insert-or-update freight items using (chain, material) as the conflict target.

class ferrosoft.apps.emiflow.models.transport.Incoterm(*values)[source]

Bases: TextChoices

Standard Incoterms® 2020 three-letter codes.

CFR = 'CFR'
CIF = 'CIF'
CIP = 'CIP'
CPT = 'CPT'
DAP = 'DAP'
DDP = 'DDP'
DPU = 'DPU'
EXW = 'EXW'
FAS = 'FAS'
FCA = 'FCA'
FOB = 'FOB'
class ferrosoft.apps.emiflow.models.transport.TCEGeoDestination(*args, **kwargs)[source]

Bases: TCEGeoPoint, UUIDModel

Geographical destination of a transport chain element.

Note that TCE’s don’t necessarily have a GEO destination. It depends on TCE’s activity_distance_type.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

additional_lines

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

city

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

company

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

country

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

country_id
first_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

house_no

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

last_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

latitude

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

longitude

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <ferrosoft.apps.emiflow.models.transport.TCEGeoPointManager object>
postal_code

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

salutation

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

salutation_id
street

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

tce

Accessor to the related object on the forward side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

tce_id
class ferrosoft.apps.emiflow.models.transport.TCEGeoOrigin(*args, **kwargs)[source]

Bases: TCEGeoPoint, UUIDModel

Geographical origin of a transport chain element.

Note that TCE’s don’t necessarily have a GEO origin. It depends on TCE’s activity_distance_type.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

additional_lines

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

city

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

company

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

country

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

country_id
first_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

house_no

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

last_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

latitude

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

longitude

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <ferrosoft.apps.emiflow.models.transport.TCEGeoPointManager object>
postal_code

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

salutation

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

salutation_id
street

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

tce

Accessor to the related object on the forward side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Restaurant.place is a ForwardOneToOneDescriptor instance.

tce_id
class ferrosoft.apps.emiflow.models.transport.TCEGeoPoint(*args, **kwargs)[source]

Bases: AddressMixin, CoordinatesMixin, UUIDModel

Abstract base for the two TCE geo-point models (origin, destination).

class Meta[source]

Bases: object

abstract = False
additional_lines

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

city

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

company

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

country

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

country_id
first_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

house_no

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

last_name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

latitude

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

longitude

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

postal_code

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

salutation

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

salutation_id
street

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.transport.TCEGeoPointManager(*args, **kwargs)[source]

Bases: Manager

Manager that upserts geo-points keyed by tce.

upsert(records)[source]

Bulk insert-or-update geo-points using tce as the conflict target.

class ferrosoft.apps.emiflow.models.transport.TCEManager(*args, **kwargs)[source]

Bases: Manager

Manager that upserts TCEs keyed by (chain, position).

upsert(records)[source]

Bulk insert-or-update TCEs using (chain, position) as the conflict target.

class ferrosoft.apps.emiflow.models.transport.TCEManagerPrefetched(*args, **kwargs)[source]

Bases: TCEManager

Variant of TCEManager that joins the operation and distance unit.

get_queryset()[source]

Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.

class ferrosoft.apps.emiflow.models.transport.TransportChain(*args, **kwargs)[source]

Bases: UUIDModel

A consignment from consignor to consignee, modelled as ordered hops.

Each hop is a TransportChainElement (TCE); the chain’s cargo is split across one or more FreightItem rows by material. Once status is POSTED the chain is immutable — delete() raises and edit forms are disabled. Generated booking documents are kept for EXPIRE_DOCUMENT_ON and garbage-collected afterwards.

exception DoesNotExist

Bases: ObjectDoesNotExist

EXPIRE_DOCUMENT_ON = datetime.timedelta(days=7)
exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

accept(visitor)[source]

Visit this chain and its related objects in canonical order.

The visitor receives callbacks in this sequence:

  1. before_chain(self)

  2. on_freight_item(item) for each freight item.

  3. on_element(element) for each transport chain element.

  4. after_chain(self)

booking_date

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

consignee

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

consignee_id
consignor

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

consignor_id
copy(new_reference)[source]

Deep-copy this chain (elements, geo-points, freight) under a new reference.

Existing emission booking records for the original chain are re-inserted attached to the new chain via a raw SQL INSERT ... SELECT to avoid recomputing them. The new chain inherits the original’s status, incoterms, simulation flag, and partners.

Return type:

TransportChain

classmethod default_document_expiry(creation_time)[source]

Return the expiry timestamp for documents created at creation_time.

Return type:

datetime

delete(*args, **kwargs)[source]

Refuse to delete unless the chain is still OPEN.

Posted chains have associated booking records and must not be removed; the call raises RuntimeError to prevent the delete from being silently lost.

documents

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

elements

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

elements_ordered()[source]

Return chain elements in position order with related operation data prefetched.

freight_items

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

freight_items_ordered()[source]

Return freight items sorted by material code with unit and material prefetched.

get_absolute_url()[source]
get_incoterms_display(*, field=<django.db.models.fields.CharField: incoterms>)
get_next_by_booking_date(*, field=<django.db.models.fields.DateField: booking_date>, is_next=True, **kwargs)
get_previous_by_booking_date(*, field=<django.db.models.fields.DateField: booking_date>, is_next=False, **kwargs)
get_status_display(*, field=<django.db.models.fields.PositiveIntegerField: status>)
get_transport_type_display(*, field=<django.db.models.fields.PositiveIntegerField: transport_type>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

incoterms

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

is_status(status)[source]

Return True when the chain is in the given booking status.

Return type:

bool

lcc_values

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

next_element_position()[source]

Return the next free position value for a new chain element.

Return type:

int

objects = <ferrosoft.apps.emiflow.models.transport.TransportChainManager object>
post_emission()[source]

Run the booking service and return the booking records it produced.

Return type:

list[EmissionBookingRecord]

prefetched_objects = <ferrosoft.apps.emiflow.models.transport.TransportChainManagerPrefetched object>
reference

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

simulation

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

status

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

sum_weight()[source]

Return the chain’s total freight weight, normalised to metric tons.

Return type:

DecimalWithUnit

transport_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.transport.TransportChainElement(*args, **kwargs)[source]

Bases: UUIDModel

TransportChainElement describes a single transport or hub operation in a transport chain.

Some characteristics for emissions calculation are defined in the operation category.

activity_distance_type

Informs how activity distance was determined.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

property activity_distance

Activity distance normalised to the canonical distance unit (4 dp).

Returns a zero DecimalWithUnit unchanged so callers can treat unset and zero distances uniformly.

property activity_distance_parameters: ActivityDistanceParameters

Bundle the distance, DAF, and geo-points needed to compute the activity distance.

Raises:

RuntimeError – When called on a hub (non-transport) element — hub TCEs use freight mass as activity, not distance.

activity_distance_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

activity_distance_unit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

activity_distance_unit_id
activity_distance_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

chain

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

chain_id
distance_adjustment_factor

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

epitype

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

geo_destination

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

geo_origin

Accessor to the related object on the reverse side of a one-to-one relation.

In the example:

class Restaurant(Model):
    place = OneToOneField(Place, related_name='restaurant')

Place.restaurant is a ReverseOneToOneDescriptor instance.

get_absolute_url()[source]
get_activity_distance_type_display(*, field=<django.db.models.fields.PositiveIntegerField: activity_distance_type>)
get_epitype_display(*, field=<django.db.models.fields.PositiveIntegerField: epitype>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <ferrosoft.apps.emiflow.models.transport.TCEManager object>
operation

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

operation_id
position

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

prefetched_objects = <ferrosoft.apps.emiflow.models.transport.TCEManagerPrefetched object>
property show_distance_adjustment_factor

Whether the form should expose the DAF input (only for actual distance).

property show_geo_points

Whether the form should expose origin/destination geo-points.

Geo-points only matter for great-circle and shortest-feasible distance computations; actual distance uses the entered number.

class ferrosoft.apps.emiflow.models.transport.TransportChainManager(*args, **kwargs)[source]

Bases: Manager

Manager that upserts transport chains keyed by reference.

upsert(records)[source]

Bulk insert-or-update chains using reference as the conflict target.

class ferrosoft.apps.emiflow.models.transport.TransportChainManagerPrefetched(*args, **kwargs)[source]

Bases: TransportChainManager

Variant of TransportChainManager that prefetches elements and LCC values.

get_queryset()[source]

Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.

class ferrosoft.apps.emiflow.models.transport.TransportChainType(*values)[source]

Bases: IntegerChoices

Direction of a transport chain relative to the booking organisation.

DROP_SHIPMENT = 3
INCOMING = 1
OUTGOING = 2
class ferrosoft.apps.emiflow.models.transport.TransportChainVisitor[source]

Bases: ABC

Visitor protocol traversed by TransportChain.accept().

Default implementations are no-ops; subclasses override only the callbacks they care about. Used by booking and report-rendering code to walk the chain without coupling either side to the iteration order.

after_chain(chain)[source]

Called once after all freight items and elements have been visited.

before_chain(chain)[source]

Called once before any freight items or elements are visited.

on_element(element)[source]

Called for each chain element, in position order.

on_freight_item(item)[source]

Called for each freight item, in material-code order.

class ferrosoft.apps.emiflow.models.transport.TransportLCCValue(*args, **kwargs)[source]

Bases: LCCValue

Custom lifecycle category values for transports.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

chain

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

chain_id
emission_unit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

emission_unit_id
get_absolute_url()[source]
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

lifecycle_category

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

lifecycle_category_id
operation_emission_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

total_emission_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

ferrosoft.apps.emiflow.models.treatment module

Treatment and treatment-operation domain models.

A TreatmentOperation is the recipe: what materials go in, what comes out, which emitter and energy carrier are involved, and how emissions should be allocated to the outputs (by weight or manually). A Treatment is a specific application of that recipe on a booking date, with its own input/output lines that can deviate from the operation defaults. Operations are certified before they can be referenced; certifying enforces that emission intensity is set and output allocations sum to 100 %.

class ferrosoft.apps.emiflow.models.treatment.Allocation(method, total_allocation, total_weight, materials)[source]

Bases: object

Snapshot of how a treatment operation’s emissions split across its outputs.

materials: List[MaterialAllocation]
method: AllocationMethod
total_allocation: Decimal
total_weight: DecimalWithUnit
class ferrosoft.apps.emiflow.models.treatment.AllocationMethod(*values)[source]

Bases: IntegerChoices

How emissions are distributed across a treatment’s output materials.

MANUALLY = 2
WEIGHT = 1
describe()[source]

Return a human-readable explanation of this allocation mode.

Return type:

str

class ferrosoft.apps.emiflow.models.treatment.MaterialAllocation(material, fraction)[source]

Bases: object

One row in an Allocation: a material and its fraction (0..1).

fraction: Decimal
material: Material
class ferrosoft.apps.emiflow.models.treatment.Treatment(*args, **kwargs)[source]

Bases: UUIDModel

A specific run of a TreatmentOperation on a booking date.

Each treatment owns its own input and output lines so the realised quantities can deviate from the recipe; emissions are posted via post_emission(), after which the treatment moves to POSTED and becomes effectively read-only.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

booking_date

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

copy_lines_from_operation()[source]

Seed input and output lines from the parent operation.

Idempotent and one-sided: each side (inputs, outputs) is only copied when no rows exist yet, so re-running the call after the user has edited one side will not overwrite their edits.

get_absolute_url()[source]
get_next_by_booking_date(*, field=<django.db.models.fields.DateField: booking_date>, is_next=True, **kwargs)
get_previous_by_booking_date(*, field=<django.db.models.fields.DateField: booking_date>, is_next=False, **kwargs)
get_status_display(*, field=<django.db.models.fields.IntegerField: status>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

inputs

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

is_status(status)[source]

Return True when the treatment is in the given status.

Return type:

bool

lcc_values

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

objects = <ferrosoft.apps.emiflow.models.treatment.TreatmentManager object>
operation

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

operation_id
outputs

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

post_emission()[source]

Run the booking service, mark the treatment posted, return the records.

No-op (returns an empty list) when the treatment is not in the OPEN status — posting is a one-way transition.

Return type:

list[EmissionBookingRecord]

reference

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

status

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.treatment.TreatmentInputLine(*args, **kwargs)[source]

Bases: TreatmentLine

Material used as input to a treatment.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

get_absolute_url()[source]
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

material: Material

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

material_id
objects = <ferrosoft.apps.emiflow.models.treatment.TreatmentInputLineManager object>
treatment: Treatment

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

treatment_id
weight_unit: MeasurementUnit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

weight_unit_id
weight_value: Decimal

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.treatment.TreatmentInputLineManager(*args, **kwargs)[source]

Bases: TreatmentLineManager

Manager that upserts input lines keyed by (treatment, material).

upsert(records)[source]

Bulk insert-or-update input lines using (treatment, material) as the conflict target.

class ferrosoft.apps.emiflow.models.treatment.TreatmentLCCValue(*args, **kwargs)[source]

Bases: LCCValue

Custom lifecycle category values for treatments.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

emission_unit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

emission_unit_id
get_absolute_url()[source]
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

lifecycle_category

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

lifecycle_category_id
operation_emission_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

total_emission_value

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

treatment

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

treatment_id
class ferrosoft.apps.emiflow.models.treatment.TreatmentLine(*args, **kwargs)[source]

Bases: UUIDModel

Abstract base for a material + weight line on either a treatment or operation.

class Meta[source]

Bases: object

abstract = False
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

material: Material

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

material_id
objects
property weight: DecimalWithUnit

Line weight paired with its unit.

weight_unit: MeasurementUnit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

weight_unit_id
weight_value: Decimal

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.treatment.TreatmentLineManager(*args, **kwargs)[source]

Bases: Manager

Manager using TreatmentLineQuerySet with material/unit prefetch.

get_queryset()[source]

Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.

class ferrosoft.apps.emiflow.models.treatment.TreatmentLineQuerySet(model=None, query=None, using=None, hints=None)[source]

Bases: QuerySet

QuerySet adding a unit-aware sum_weight aggregation.

sum_weight()[source]

Return the sum of all line weights, normalised to metric tons.

Return type:

DecimalWithUnit

class ferrosoft.apps.emiflow.models.treatment.TreatmentManager(*args, **kwargs)[source]

Bases: Manager

Manager that prefetches operation, inputs, outputs, and LCC values.

get_queryset()[source]

Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.

upsert(records)[source]

Bulk insert-or-update treatments using reference as the conflict target.

class ferrosoft.apps.emiflow.models.treatment.TreatmentOperation(*args, **kwargs)[source]

Bases: UUIDModel

A reusable treatment recipe (inputs, outputs, emitter, allocation).

Operations move through TreatmentOperationStatus from Open to Certified; certification is gated by certification_errors() (intensity present + outputs allocated 100 %). Only certified operations are intended to be referenced by Treatment rows.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

allocation_method

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

certification_errors()[source]

Return user-facing reasons the operation cannot yet be certified.

Currently checks that an EmissionIntensity is attached and that output allocations sum to exactly 100 %. Returns an empty list when the operation is ready to certify.

Return type:

List[str]

certify()[source]

Try to certify the operation; return the blocking errors if any.

On success the status is moved to CERTIFIED and the empty list is returned. On failure the status is left unchanged and the caller-facing error messages from certification_errors() are returned.

Return type:

List[str]

emission_intensity

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

emission_intensity_id
emitter

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

emitter_id
energy_carrier

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

energy_carrier_id
get_absolute_url()[source]
get_allocation_method_display(*, field=<django.db.models.fields.IntegerField: allocation_method>)
get_output_allocation()[source]

Bundle the current method, totals, and per-material allocations.

Return type:

Allocation

get_status_display(*, field=<django.db.models.fields.IntegerField: status>)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

inputs

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

is_status(status)[source]

Return True when the operation is in the given status.

Return type:

bool

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <ferrosoft.apps.emiflow.models.treatment.TreatmentOperationManager object>
outputs

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

reference

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

reopen()[source]

Move the operation back from CERTIFIED to OPEN.

status

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

treatment_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

trigger_allocation()[source]

Recompute allocated_fraction on every output line from its weight.

No-op when the operation uses manual allocation. Called from the post-save / post-delete signals on TreatmentOperationOutputLine so the allocation stays consistent whenever an output is added, edited, or removed.

class ferrosoft.apps.emiflow.models.treatment.TreatmentOperationInputLine(*args, **kwargs)[source]

Bases: TreatmentLine

Material used as input to a treatment operation.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

get_absolute_url()[source]
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

material: Material

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

material_id
objects = <ferrosoft.apps.emiflow.models.treatment.TreatmentOperationInputLineManager object>
operation: TreatmentOperation

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

operation_id
weight_unit: MeasurementUnit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

weight_unit_id
weight_value: Decimal

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.treatment.TreatmentOperationInputLineManager(*args, **kwargs)[source]

Bases: TreatmentLineManager

Manager that upserts operation input lines keyed by (operation, material).

upsert(records)[source]

Bulk insert-or-update lines using (operation, material) as the conflict target.

class ferrosoft.apps.emiflow.models.treatment.TreatmentOperationManager(*args, **kwargs)[source]

Bases: Manager

Manager that prefetches inputs, outputs, emitter, and energy carrier.

get_queryset()[source]

Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.

upsert(records)[source]

Bulk insert-or-update operations using reference as the conflict target.

class ferrosoft.apps.emiflow.models.treatment.TreatmentOperationOutputLine(*args, **kwargs)[source]

Bases: TreatmentLine

Material returned by a treatment operation.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

allocated_fraction

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_absolute_url()[source]
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

material: Material

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

material_id
objects = <ferrosoft.apps.emiflow.models.treatment.TreatmentOperationOutputLineManager object>
operation: TreatmentOperation

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

operation_id
weight_unit: MeasurementUnit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

weight_unit_id
weight_value: Decimal

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.treatment.TreatmentOperationOutputLineManager(*args, **kwargs)[source]

Bases: TreatmentLineManager

Manager with allocation aggregation and upsert helpers.

sum_allocation()[source]

Return (total_weight_in_t, total_allocated_fraction) for the queryset.

Weights are summed per unit at the database layer and then converted to metric tons in Python so a mix of input units does not produce a meaningless total.

Return type:

tuple[DecimalWithUnit, Decimal]

upsert(records)[source]

Bulk insert-or-update output lines using (operation, material) as the conflict target.

class ferrosoft.apps.emiflow.models.treatment.TreatmentOperationStatus(*values)[source]

Bases: IntegerChoices

Lifecycle state of a TreatmentOperation (certified ops can be referenced by treatments).

CERTIFIED = 2
OPEN = 1
class ferrosoft.apps.emiflow.models.treatment.TreatmentOutputLine(*args, **kwargs)[source]

Bases: TreatmentLine

Material returned by a treatment.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

allocated_fraction

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_absolute_url()[source]
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

material: Material

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

material_id
objects = <ferrosoft.apps.emiflow.models.treatment.TreatmentOutputLineManager object>
treatment: Treatment

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

treatment_id
weight_unit: MeasurementUnit

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

weight_unit_id
weight_value: Decimal

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class ferrosoft.apps.emiflow.models.treatment.TreatmentOutputLineManager(*args, **kwargs)[source]

Bases: TreatmentLineManager

Manager that upserts output lines keyed by (treatment, material).

upsert(records)[source]

Bulk insert-or-update output lines using (treatment, material) as the conflict target.

class ferrosoft.apps.emiflow.models.treatment.TreatmentStatus(*values)[source]

Bases: IntegerChoices

Lifecycle state of a Treatment (posted treatments are immutable).

OPEN = 1
POSTED = 2