> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firstresonance.io/llms.txt
> Use this file to discover all available pages before exploring further.

# LinkRunStepToPurchaseOrder

> Link an OSP run step to a purchase order. The backend resolves the correct action: - Part exists on PO (with or without inventory) → add run's inventory to that line. The PO line's quantity and part_id are left unchanged. - Part not on PO → create a new PO line (quantity from run's inventory). When the run is already linked to a different PO, only the POLI record for this run's inventory is removed from the old line — the old PO line itself is preserved along with any other runs' inventories on it. ``applyToAllRunStepsInBatch`` controls batch propagation. When the run step is part of a normalized batch and the flag is ``true`` (the default), the link is also applied to every batch sibling whose step is not terminal and whose run has a part inventory — including siblings currently linked elsewhere, which are moved to the target line. Set the flag to ``false`` to link only the specified run step. Errors: rejected with a ValidationError when the primary OR any sibling that this call would touch has been received — either the parent PO line's status is ``RECEIVED``, or the specific part inventory has already been recorded against a receipt for its current line (the line stays ``ORDERED`` for serial-tracked lines with multiple POLIs until every POLI is received, but each individually received POLI is locked from that moment on). Received POLIs are part of the receipt audit trail and cannot be moved.

