Skip to content

Add Lines from Items.

Description

The user can select a set of Items from the Item List and create a Purchase Order with PoLines for each selected item. The user can then edit the Order as in the previous cases.

  • The creation will fail if the selected items don’t have a shared vendor (blank primary and secondary suppliers is considered a match with any other item).
  • The Quantities of the PoLines will be set to the minQuantity of the item if available or 0 eaches otherwise.

Requirement

Create an order (header + lines) from a caller-supplied list of Item identifiers.
Implementation entry point: OrderFromItemsService.addOrderFromItems (operations/src/main/kotlin/cards/arda/operations/procurement/orders/service/OrderFromItemsService.kt).

Preconditions

  • The items collection must contain at least one entry and cannot exceed LineUniverse.MAX_PAGE_SIZE (currently 1000); otherwise an ArgumentValidation error is returned (OrderFromItemsService.kt:29-33, 60-73).
  • Every requested Item must exist at TimeCoordinates.now(effectiveTime); missing items result in a NotFound error before any persistence (OrderFromItemsService.kt:74-84).
  • Items must share a compatible supplier according to OrderHelper.selectCompatibleSupply; if no shared supplier exists among items that have a preferred supply, the call fails with IllegalArgumentException (operations/src/main/kotlin/cards/arda/operations/procurement/orders/service/OrderHelper.kt:134-147).

Scenario Overview

  1. Load all requested Items via ItemService.listEntities. Items are processed as of the effective timestamp specified (OrderFromItemsService.kt:74-84).
  2. Build draft order lines by calling OrderHelper.composeLine for each item, producing placeholder lines with generated eIds (OrderFromItemsService.kt:85-87).
  3. Compose a provisional header with defaults (OrderStatus.NEW, allowPartial=true, deliverBy = now + 7 days, etc.) using OrderHelper.composeHeader (operations/src/main/kotlin/cards/arda/operations/procurement/orders/service/OrderHelper.kt:261-283).
  4. Enrich every line with supplier-driven details (title, quantity, unit cost) via OrderHelper.adjustLine, and recompute the header (supplier, goods value) through OrderHelper.adjustHeader (OrderFromItemsService.kt:88-91).
  5. Persist the header and lines in a single transaction with OrderHelper.addOrderWithLines, invoking any supplied postProcess callback after persistence (OrderFromItemsService.kt:92-93).

PostConditions

  • A new OrderRecord (header plus paginated lines) is stored and returned on success.
  • Goods value is derived from the enriched line costs when supplier data is available; otherwise it remains null.
  • No Kanban card associations are created by this flow.

Creation of Order Lines

  • Each line references the selected item through ItemReference.Value.fromItem.
  • Quantities default to the supplier’s reorder quantity when available; when not, they remain null. The implementation does not use Item.minQuantity, contrary to earlier plans.
  • Unit cost is copied from the effective supply without verifying unit compatibility (the service assumes OrderHelper.adjustLine produced a coherent quantity).

Changes to Order Header

  • supplierName is derived from the compatible supplier returned by selectCompatibleSupply; if none is found the field remains null.
  • orderMethod reflects the shared effective supply method when consistent, or OrderMethod.UNKNOWN otherwise (OrderHelper.kt:165-176).
  • goodsValue is recomputed from enriched lines during adjustHeader; if any line references an item missing supply data, the goods value may remain null.

Comments