ferrosoft.apps.emiflow.services.businesscentral package¶
Adapters for the Microsoft Dynamics 365 Business Central integration.
connectorposts calculated emissions to the BC connector microservice.rapidstartexports catalog and operation reference data as a gzipped RapidStart XML package that can be imported into a BC company.
Submodules¶
ferrosoft.apps.emiflow.services.businesscentral.connector module¶
HTTP client for the Business Central connector microservice.
Calculated transport emissions are POSTed to the BC connector, which
relays them into a customer’s Business Central tenant. The JSON
payload uses the BC field-name conventions (camelCase); units are
flattened to {"value": ..., "unit": ...} shapes by _decimal().
- class ferrosoft.apps.emiflow.services.businesscentral.connector.BcConnectorClient[source]¶
Bases:
ABCAbstract BC connector client. Production singleton is
BcConnectorHTTPClient.
- class ferrosoft.apps.emiflow.services.businesscentral.connector.BcConnectorHTTPClient(config)[source]¶
Bases:
BcConnectorClientHTTP implementation of
BcConnectorClient.Uses a long-lived JWT (loaded from Django settings) as the bearer token; the connector identifies tenants by the Ferrosoft tenant UUID embedded in the payload.
- class Config(base_url, jwt)[source]¶
Bases:
objectEndpoint URL and bearer token for the connector.
- post_emission(emission, element_emissions, tenant=None)[source]¶
POST one chain’s emissions (plus per-element breakdown) to the connector.
- Raises:
ClientError – When the JWT is not configured.
RuntimeError – When the connector returns a non-200 status.
- exception ferrosoft.apps.emiflow.services.businesscentral.connector.ClientError[source]¶
Bases:
ErrorConfiguration or request-time failure in the BC connector client.
- exception ferrosoft.apps.emiflow.services.businesscentral.connector.Error[source]¶
Bases:
RuntimeErrorBase class for BC connector errors.
ferrosoft.apps.emiflow.services.businesscentral.rapidstart module¶
Export emiflow reference data as a Business Central RapidStart package.
RapidStart is BC’s bulk-import format: a gzipped XML document with one
<TableNameList> per BC table, each holding the row data plus
field metadata (TableID, PageID, ValidateField,
ProcessingOrder, PrimaryKey). The
ModelSerializerMeta metaclass registers each subclass with
SerializerSwitch so RapidstartExporter can iterate
the registered models in dependency order and assemble the complete
DataList element.
Numbers in BC have a maximum length (20 chars), so primary keys are
derived from the last seven characters of each Ferrosoft UUID via
derive_bc_number().
- class ferrosoft.apps.emiflow.services.businesscentral.rapidstart.CatalogSerializer[source]¶
Bases:
ModelSerializerSerializer mapping
EmissionsCatalogto theCatalogFERtable.- model¶
alias of
EmissionsCatalog
- class ferrosoft.apps.emiflow.services.businesscentral.rapidstart.ClassAttributes(attrs)[source]¶
Bases:
objectValidator for class-attribute presence used by
ModelSerializerMeta.
- ferrosoft.apps.emiflow.services.businesscentral.rapidstart.Element(tag, text=None, children=None, attrib=None, **extra)[source]¶
Construct an
ElementTreeelement in one expression.Convenience wrapper that accepts
textandchildreninline so RapidStart documents read close to the XML they produce.- Return type:
- class ferrosoft.apps.emiflow.services.businesscentral.rapidstart.EmitterSerializer[source]¶
Bases:
ModelSerializerSerializer mapping
Emitterto theEmitterFERtable.
- class ferrosoft.apps.emiflow.services.businesscentral.rapidstart.EnergyCarrierSerializer[source]¶
Bases:
ModelSerializerSerializer mapping
EnergyCarrierto theEnergyCarrierFERtable.- model¶
alias of
EnergyCarrier
- class ferrosoft.apps.emiflow.services.businesscentral.rapidstart.MeasurementUnitSerializer[source]¶
Bases:
ModelSerializerSerializer mapping ferrobase
MeasurementUnitto BCUnit of Measure.- model¶
alias of
MeasurementUnit
- class ferrosoft.apps.emiflow.services.businesscentral.rapidstart.ModelSerializer[source]¶
Bases:
objectBase class for a serializer that emits one BC RapidStart table.
Subclasses declare
model,table_id,table_name, andpage_idas class attributes and implementserialize_fields()to return the per-record XML children. The first record gets full field metadata (ValidateField/ProcessingOrder/PrimaryKey); later records re-use it implicitly. Setprimary_keyto a list of field names when the table has a composite primary key.- model = None¶
- class ferrosoft.apps.emiflow.services.businesscentral.rapidstart.ModelSerializerMeta(name, bases, attrs, **kwargs)[source]¶
Bases:
typeMetaclass that auto-registers each
ModelSerializerwith the switch.
- class ferrosoft.apps.emiflow.services.businesscentral.rapidstart.RapidstartExporter[source]¶
Bases:
objectAssemble and gzip the complete RapidStart
DataListpackage.Iterates
modelsin dependency order (units → catalog → energy carriers → emitters → operations → operation lines) so that foreign-key targets always precede the rows that reference them in the resulting XML.
- class ferrosoft.apps.emiflow.services.businesscentral.rapidstart.SerializerSwitch[source]¶
Bases:
objectRegistry mapping
Modelclasses to theirModelSerializer.- classmethod serialize(model)[source]¶
Run the registered serializer for
modeland return its element.Raises
RuntimeErrorwhen no serializer is registered.- Return type:
- class ferrosoft.apps.emiflow.services.businesscentral.rapidstart.TransportOperationSerializer[source]¶
Bases:
ModelSerializerSerializer mapping
TransportOperationto theTransportOperationFERtable.- model¶
alias of
TransportOperation
- class ferrosoft.apps.emiflow.services.businesscentral.rapidstart.TreatmentOperationInputLineSerializer[source]¶
Bases:
ModelSerializerSerializer for
TreatmentOperationInputLinerows (composite PK).- model¶
alias of
TreatmentOperationInputLine
- primary_key = ['OperationNo', 'MaterialNo']¶
- class ferrosoft.apps.emiflow.services.businesscentral.rapidstart.TreatmentOperationOutputLineSerializer[source]¶
Bases:
ModelSerializerSerializer for
TreatmentOperationOutputLinerows (composite PK).- model¶
alias of
TreatmentOperationOutputLine
- primary_key = ['OperationNo', 'MaterialNo']¶
- class ferrosoft.apps.emiflow.services.businesscentral.rapidstart.TreatmentOperationSerializer[source]¶
Bases:
ModelSerializerSerializer mapping
TreatmentOperationtoTreatmentOperationFER.Only certified operations are exported — open operations are still being authored and would mislead downstream BC bookings.
- model¶
alias of
TreatmentOperation
- ferrosoft.apps.emiflow.services.businesscentral.rapidstart.derive_bc_number(default_prefix)[source]¶
Return a function that turns a UUID into a BC-friendly No. string.
The returned closure derives a string of the form
"{prefix}{LAST_7_HEX_UPPER}";prefixdefaults todefault_prefixbut each call can override it (e.g. to reuse another model’s prefix when emitting a foreign-key reference).