PhoenixKitWarehouse.DocRefs (PhoenixKitWarehouse v0.1.0)

Copy Markdown View Source

Resolves warehouse document UUIDs to human-readable labels and admin paths.

All functions come in single (ref) and batch (refs) variants to avoid N+1 queries when rendering index pages.

Returned maps have the shape: %{label: "#IO-N", path: "/admin/warehouse/internal-orders/<uuid>",

uuid: "<uuid>", kind: :internal_order}

label, uuid, and kind are always present; path is always absolute. kind is one of :order, :sub_order, :internal_order, :supplier_order, :goods_receipt, :goods_issue — useful for grouping a resolved list by tier. Functions return nil when the UUID is nil or the document does not exist.

Summary

Functions

Resolves a single goods issue UUID to a label/path map. Returns nil when uuid is nil or not found.

Batch resolves a list of goods issue UUIDs. Returns %{uuid => ref_map}.

Returns all non-deleted goods issue refs where internal_order_uuid = the given uuid. Returns a list of ref maps [%{label, path}].

Resolves a single goods receipt UUID to a label/path map. Returns nil when uuid is nil or not found.

Batch resolves a list of goods receipt UUIDs. Returns %{uuid => ref_map}.

Resolves a single internal order UUID to a label/path map. Returns nil when uuid is nil or not found.

Batch resolves a list of internal order UUIDs. Returns %{uuid => ref_map} (absent uuids are omitted).

Resolves a top-level order UUID to a label/path map.

Resolves a list of source_ref maps to label/path maps.

Resolves a sub-order UUID to a label/path map via SourceKinds.resolve/2.

Batch resolves a list of sub-order UUIDs. Returns %{uuid => ref_map}.

Resolves a single supplier order UUID to a label/path map. Returns nil when uuid is nil or not found.

Batch resolves a list of supplier order UUIDs. Returns %{uuid => ref_map}.

Returns all non-deleted supplier order refs where internal_order_uuid = the given uuid. Returns a list of ref maps [%{label, path}].

Functions

goods_issue_ref(uuid)

Resolves a single goods issue UUID to a label/path map. Returns nil when uuid is nil or not found.

goods_issue_refs(uuids)

Batch resolves a list of goods issue UUIDs. Returns %{uuid => ref_map}.

goods_issue_refs_for_internal_order(internal_order_uuid)

Returns all non-deleted goods issue refs where internal_order_uuid = the given uuid. Returns a list of ref maps [%{label, path}].

goods_receipt_ref(uuid)

Resolves a single goods receipt UUID to a label/path map. Returns nil when uuid is nil or not found.

goods_receipt_refs(uuids)

Batch resolves a list of goods receipt UUIDs. Returns %{uuid => ref_map}.

internal_order_ref(uuid)

Resolves a single internal order UUID to a label/path map. Returns nil when uuid is nil or not found.

internal_order_refs(uuids)

Batch resolves a list of internal order UUIDs. Returns %{uuid => ref_map} (absent uuids are omitted).

order_ref(uuid)

Resolves a top-level order UUID to a label/path map.

Returns nil when uuid is nil, not found, or the record is a sub-order (has a parent_uuid).

refs_for(source_refs)

Resolves a list of source_ref maps to label/path maps.

Each element must have shape %{"type" => type, "uuid" => uuid} where type is one of:

  • "order" — host-registered order kind
  • "sub_order" — host-registered sub-order kind
  • "internal_order" — warehouse internal order
  • "supplier_order" — warehouse supplier order
  • "goods_receipt" — warehouse goods receipt
  • "goods_issue" — warehouse goods issue

Returns a list of %{label, path} maps, omitting any that resolve to nil (e.g. deleted or not-found documents).

sub_order_ref(uuid)

Resolves a sub-order UUID to a label/path map via SourceKinds.resolve/2.

Returns nil when uuid is nil or SourceKinds returns :error (no host registered a "sub_order" resolver, or the document was not found).

sub_order_refs(uuids)

Batch resolves a list of sub-order UUIDs. Returns %{uuid => ref_map}.

Note: resolves via individual sub_order_ref/1 calls (one SourceKinds.resolve/2 per uuid) rather than a single batched query, due to the SourceKinds single-uuid contract (Plan 2). Acceptable given typical list sizes; revisit in Plan 5 if query count becomes a problem in practice.

supplier_order_ref(uuid)

Resolves a single supplier order UUID to a label/path map. Returns nil when uuid is nil or not found.

supplier_order_refs(uuids)

Batch resolves a list of supplier order UUIDs. Returns %{uuid => ref_map}.

supplier_order_refs_for_internal_order(internal_order_uuid)

Returns all non-deleted supplier order refs where internal_order_uuid = the given uuid. Returns a list of ref maps [%{label, path}].