feat: operational resource procurement facility

Implement RESOURCE-WP-0005: entity register, V0.1 terms parameters,
entity association on inventory and planning records, transfer-price
and credit-state arithmetic, monthly settlement, and entity views on
the portfolio report. Live close emits nothing until delivered cost
is known. Handoffs are FIN-WP-0006 and RAILIANCE-WP-0017.
This commit is contained in:
tegwick 2026-08-14 13:15:02 +02:00
parent 325a505980
commit f8d1c542d5
37 changed files with 1316 additions and 28 deletions

View file

@ -4,9 +4,11 @@
import json
from pathlib import Path
from entities import REQUIRED_ENTITY_IDS, load_register, load_terms, require_entity, validate_register, validate_terms
from optimization import validate_case
from portfolio import validate_record
from portfolio_report import build as build_portfolio_report
from settlement import close_fixture, close_live
def load(path: str) -> dict:
@ -85,6 +87,33 @@ def main() -> int:
assert report["resource_count"] == len(resource_paths) - len(list(Path("examples/portfolio").glob("*.json")))
assert report["cost"]["known_monthly_spend_eur"] is None
assert report["next_actions"]
register_payload = load("data/entities/register.json")
terms_payload = load("data/terms/procurement-v0.1.json")
entities = validate_register(register_payload)
terms = validate_terms(terms_payload)
_, loaded_entities = load_register(Path("."))
assert loaded_entities.keys() == entities.keys()
assert list(entities) == list(REQUIRED_ENTITY_IDS) or set(entities) == set(REQUIRED_ENTITY_IDS)
assert terms["markup_rate"] == load_terms(Path("."))["markup_rate"]
try:
require_entity("entity:unknown")
raise AssertionError("unknown entity id must be rejected")
except ValueError as exc:
assert "unknown entity id" in str(exc)
entity_ids = {row["financial_entity_id"] for row in report["entities"]["entities"]}
assert entity_ids == set(REQUIRED_ENTITY_IDS)
assert report["entities"]["known_monthly_spend_eur"] is None
assert report["entities"]["unattributed_resources"]
live_statements = close_live(Path("."), "2026-08")
assert live_statements == []
fixture_dir = Path("examples/settlement")
ordinary = close_fixture(load(str(fixture_dir / "15.1-ordinary.json")), terms, entities)
assert len(ordinary) == 1
assert ordinary[0]["known_transfer_price_eur"] == "240.00"
planning = load("examples/planning/entity-forecast-transfer.json")
assert planning["transfer_price"] == "240.00"
assert planning["credit_headroom"] == "760.00"
assert planning["financial_entity_id"] == "entity:coulomb"
print("resource-control declarations: valid")
return 0