ERP / Inventory Node Type: the read/write split, and its own reporting channel
This guide covers how the ERP/Inventory Node Type builds on RestPollingConnector, the REST-polling System Connector. Which connector section each Node Type reads:
| Node Type | Section |
|---|---|
| ERP / Inventory, Production Scheduling | rest |
| MES | opcua, mqtt or database_log |
| PLC / Generic Device | opcua or mqtt |
ERP/Inventory's role is read/write access to material consumption and availability. That is two genuinely different mechanisms, not one ingestion pipeline handling four event types:
- Read:
ErpIngestioninengine/erp_ingestion.py. It handles Material identity, resolved at whichever granularity (serial, lot, bulk) this Node instance is configured for. It is the only part of this Node Type that polls its own target system. - Write:
ErpReportinginengine/erp_reporting.py. It delivers an already-canonical event (OrderRelease,OrderCompletion,CostingMilestone) outward to the real ERP system, exactly once.- These three do not originate at ERP. Order Release and Completion originate at MES, and Costing Milestone's labor, material and machine-time actuals are floor-domain data too.
- This half therefore runs no Identity Resolution or Data Transformation Layer step of its own. That already happened once, at whichever node originated the event.
See node-types/erp/README.md for the Node Type Agreement shape (the four event_types in node_type.json, and the field_map and material_granularity in example_config.json). This guide is the runnable picture of both halves plus their pitfalls.
1. The read half: ErpIngestion
from engine.erp_config import build_material_granularity, build_rest_connector_profile
from engine.erp_ingestion import ErpIngestion
from engine.identity_resolution import IdentityResolver, IdentityStore
from engine.transformation import TransformationRegistry, build_petl_transform
from engine.trigger_queue import TriggerQueue
rest_config = {
"endpoint": "...",
"api_key": "...",
"field_map": {"material_id": "lot_number"},
"material_granularity": "lot",
}
profile = build_rest_connector_profile(rest_config) # RestConnectorProfile, for the connector
granularity = build_material_granularity(rest_config) # "lot" — this instance's own default
registry = TransformationRegistry()
registry.register("erp-rest-material", build_petl_transform({"material_id": "lot_number"}))
resolver = IdentityResolver(IdentityStore(), activity_log, "ERP", node_instance_id)
ingestion = ErpIngestion(
transformation_registry=registry,
identity_resolver=resolver,
trigger_queue=TriggerQueue(),
node_instance_id=node_instance_id,
material_granularity=granularity,
)
envelope = ingestion.ingest(
"erp-rest-material",
raw_record, # e.g. {"lot_number": "LOT-4521"}
trigger_type="material_observed",
trigger_id=stable_id,
)
How it relates to MES ingestion
ingest() shares ingest_and_enqueue (engine/ingestion_pipeline.py) with MesIngestion (engine/mes_ingestion.py). It is the same map, resolve and enqueue composition, differing only in:
entity_type, which isEntityType.MATERIAL;identity_field, which is"material_id";default_fields={"granularity": material_granularity}, which isErpIngestion's own addition with no MES analogue.
material_granularity=None is legal at construction, but ingest() itself raises ConfigValidationError. The check happens before the Data Transformation Layer runs, so a misconfigured instance fails immediately rather than paying for a transform pass whose result gets discarded.
Per-record granularity wins
A record's own field_map-reported granularity always wins over the configured default. The schema (MaterialObserved in node-types/erp/node_type.json) permits field_map: {"granularity": ...} as an ordinary target, for an integrator whose source data reports per-record granularity. The default only fills a gap: no key, or an explicit None (see Pitfalls).
2. The write half: ErpReporting
from engine.activity_log import ActivityLog
from engine.connector import RestPollingConnector
from engine.erp_reporting import ErpReporting
connector = RestPollingConnector(profile) # same RestConnectorProfile built above
reporting = ErpReporting(
connector=connector, activity_log=activity_log, node_instance_id=node_instance_id
)
result = reporting.report(
{"order_id": "MO-9001", "status": "in-progress"}, # already-canonical — no mapping here
trigger_type="order_release",
report_id=stable_id, # Milestone delivery guarantee's own stable ID
)
# result.outcome: Outcome.SUCCEEDED / Outcome.GAVE_UP (engine/try_catch.py)
How a report reaches it
report() takes canonical event fields directly, not a raw record. The Communication Interface (the node-to-node protocol) carries MES's report to it:
- MES sends a
reportquery (REPORT_QUERYandreport_event_to_erpinengine/erp_reporting_wiring.py), called from_order_release_stepand_costing_variance_point_builderinengine/node_main.py. - The ERP Node's listener answers it with
_answer_report(engine/erp_main.py). - That calls
ErpReporting.report(). Seeerp-runtime-entrypoint.md.
Delivery behavior
- Idempotency.
report_idis carried as anIdempotency-Keyheader on every attempt, including retries and a genuine redelivery. The closure captures it once, outside the retried step, so a receiving ERP system can dedupe rather than double-post cost. - Retries. Retried under
TryCatch/RetryPolicy(default 3 attempts). An unresponsive ERP endpoint isUnresponsiveServiceFailure, the same Try/Catch path any other external-target call uses, not a bespoke retry loop. - Logging. It runs through
log_task_executionunderTASK_TYPE_REPORT("reporting"), even though no AI reasoning is involved. The Activity Log's job is a complete record including writes back to a connected system.IdentityResolver's RULE-mode Gate established the same reasoning.
Why Costing Milestone carries no standard cost
CostingMilestone deliberately carries no standard or budgeted cost field. That is ERP's own reference data already, and genuinely dynamic (periodic cost rolls, for example), so reporting it back would be circular. It stays queryable live by whichever node runs a variance check, through the Communication Interface, never baked into a reported payload.
3. Configuration: engine/erp_config.py
This module mirrors engine/opcua_config.py's shape for the rest config fragment. REST_CONFIG_SCHEMA is kept in sync with config_schema.rest in node-types/erp/node_type.json by hand.
build_field_mapandbuild_state_transition_rulesare scoped to the read half only. The three reported-outward event types arrive pre-canonicalized and need no mapping of their own.build_poll_interval_secondsandbuild_standard_cost_pathread the poll cadence and the live standard-cost path for the runtime entrypoint.build_material_granularityhas no OPC UA analogue. It is this Node Type's declared-once-per-instance default, separate fromfield_mapbecause a mapped field name alone doesn't say whether it is a serial, a lot, or a bulk reference.
The rest keys:
| Key | Notes |
|---|---|
endpoint |
Required. |
api_key |
Required. The key is sensitive. |
auth_path, poll_path, report_path |
|
timeout_seconds |
Above 0. |
field_map, state_transition_rules |
|
material_granularity |
|
poll_interval_seconds |
Above 0. |
standard_cost_path |
The connector
RestPollingConnector (engine/connector.py) behaves as follows:
- It authenticates with a POST to
auth_pathcarryingapi_key, and caches the returned bearer token across calls. - Both
poll()andreport()re-authenticate once and retry on a 401, through a shared_authenticated_call(). A target system's token can expire between calls without that being a genuine connectivity failure. - It is registered with the connector registry as connector type
rest_polling(build_rest_polling_connectorinengine/connector.py).engine/connector_builders.pymaps therestsection of the ERP and Production Scheduling Node Types to it. - Constructing it directly also works (
build_rest_connector_profileinerp_config.pyplusRestPollingConnector(profile)), as both halves' own tests do.
Pitfalls
- A Node Type's defined role names its actual role: "channel for reporting outward", not "polls and originates". Order Release, Order Completion and Costing Milestone originate at MES and are floor-domain data reported outward to ERP, not read from it, so ERP/Inventory does not poll for them. That is why the Node Type is two structurally different mechanisms sharing one Node Type Agreement, not one pipeline:
ErpIngestion(read, Material only) andErpReporting(write, the other three). Reread a Node Type's defined role for event directionality before assuming "this Node Type'sevent_typeslist = things it polls for." default_fieldsare merged into both theIdentityObservation's attributes and the envelope'sevent_fields.MaterialObserved's declared"granularity"field is required in the emitted payload, so a default that reached only the internalIdentityRecordwould leave it unpopulated. A schema-validnode_type.jsonand tests that check onlyIdentityRecord.attributesboth miss that. Testenvelope.event_fieldsfor any field the schema requires.- A collision guard that is stricter than the schema it guards is a self-inflicted outage. The
MaterialObservedschema permitsfield_map: {"granularity": ...}as an ordinary target, so an integrator can read per-record granularity straight off source data. A hardValueErroron anydefault_fields/canonical key collision would fail on every record in that configuration, an outage that only shows once live data arrives. Instead,default_fieldsuse default-fill semantics: a record's own value wins, and a default only fills a gap. No collision is possible. - A default-fill must check value presence, not key presence.
build_petl_transformmaps afield_map-declared source field that a specific record does not carry to an explicitcanonical["granularity"] = None, not an omitted key.- The default therefore applies when
canonical.get(k) is None, not whenk not in canonical. Otherwise the explicitNonebeats the configured default and produces aMaterialObservedpayload with"granularity": None, which the schema (nonulladmitted) rejects. - Whenever a default-fill sits downstream of a mapping layer that can produce declared-but-empty fields, write a test of exactly that shape: "a
field_mapdeclares the mapping, this one record doesn't carry that column".
default_fieldsmay not target the two reserved keys.- A caller passing
default_fieldsthat targetsidentity_field(for example"material_id") orSTATUS_FIELD("status") is rejected. Those two fields drive which entity a record resolves against and what status the envelope reports. Silently defaulting either would change resolution or status with no signal it happened. It is almost certainly a caller typo, not a legitimate default. - The guard is scoped to just those two keys, not any domain field.
ErpIngestion'sdefault_fields={"granularity": ...}never hits it. tests/test_ingestion_pipeline.pycovers the guard directly, since neitherMesIngestion(passes nodefault_fields) norErpIngestion(fixed, non-colliding value) exercises it through its call site.- The guard and the envelope's
status=canonical.get(STATUS_FIELD)assembly both read one sharedSTATUS_FIELDconstant (engine/ingestion_pipeline.py), so a rename of the canonical status field cannot update one and miss the other.
- A caller passing
Release: v0.11.0