Skip to main content

Clone Lines from Sales Order

POST 

/api/sales-orders/ocr/:extraction_id/clone-from

Clone confirmed lines from a prior sales order into this extraction's lines_data.

Used when the extraction's customer history (or LLM analysis on email-body extractions) suggests this PO is a repeat order — the reviewer can pull lines from a previous confirmed sales order in one click instead of editing line by line.

Request body:

  • sales_order_id (required, integer) — the source sales order to clone from. Must belong to the same customer as the extraction (when extraction has a customer_id set).

Behavior:

  • Replaces (or merges with) lines_data on the extraction with one entry per source order line.
  • Each cloned line records the matched product (sku, name, average cost) and a unit price computed as amount / quantity.
  • Lines whose product is archived or missing are still copied but flagged match_status: unmatched so the reviewer must reassign.
  • Sets clone_of_sales_order_id on the extraction so the UI can show the "cloned from" banner.

Returns the updated SalesOrderOcrExtraction resource (with cloneOfSalesOrder eager-loaded).

Errors:

  • 422 — Confirmed extractions cannot be modified (only when the extraction is locked: status='confirmed' AND sales_order_id is non-null. Orphaned confirmed extractions — where the linked sales order was deleted and the FK nullOnDelete() cleared sales_order_id — are treated as unlocked and can be re-cloned).
  • 422 — Source order belongs to a different customer than the extraction.
  • 404 — Source sales order not found.
  • 422 — Validation: sales_order_id is required and must exist in sales_orders.

Request

Responses

Successful response