aps-agent/tests/intake_recovery_fixture.py

24 lines
1.0 KiB
Python
Raw Permalink Normal View History

"""Reproduce the former generic importer using the actual source workbook."""
from __future__ import annotations
import copy
def seed_legacy_intake(world, next_id, preview):
from server.aps_domain.importers import apply_import_commit
batches = []
kinds = {"products": "materials", "inventory": "materials", "materials": "materials",
"equipment": "equipment", "bom": "bom", "routing": "routing", "orders": "orders"}
for batch in preview["batches"]:
if batch.get("role") not in kinds:
continue
rows = copy.deepcopy(batch["okRows"])
for row in rows:
for key in ("sourceProfile", "profileDigest", "sourceRef", "sourceValues", "provenance", "isSandbox", "orderType"):
row.pop(key, None)
if batch["role"] == "orders":
row["deliveryDate"] = row["dueDate"]
batches.append({"kind": kinds[batch["role"]], "okRows": rows, "sheet": batch["sheet"]})
return apply_import_commit(world, next_id, batches)