# duplicatePurchaseOrder

## Overview

Clones an existing purchase order into a new DRAFT.

**Header fields copied:** companyId, supplierAccountId, receivingSiteId, externalSupplierOrderReference.

**Line fields copied per row:** itemId, quantity, unitPrice, unitId, receivingSiteId.

**Date fields reset (intentional):** orderDate defaults to today on the new draft. The order date represents a time-specific commitment and should not be silently inherited from the source PO.

**Not copied (intentional):** orderStatus, revisionNumber, docNumber, approval/rejection metadata, and inbound shipments — the new PO is a fresh DRAFT with no history.

Returns the new PO's id and auto-generated docNumber so the UI can navigate directly to the new draft's edit screen. Available regardless of source PO status.

## Modules Commands Used

- [purchase] CreatePurchaseOrder

## Exception Handling

| Error Code | Description |
| --- | --- |
| PURCHASE_COMPANY_NOT_FOUND | The source PO's company no longer exists |
| PURCHASE_CURRENCY_MISMATCH | The source PO's currency is no longer the company's base currency |
| PURCHASE_SUPPLIER_NOT_FOUND | The source PO's supplier no longer exists |
| PURCHASE_SUPPLIER_NOT_ACTIVE | The source PO's supplier has been deactivated since the original PO was created |
| PURCHASE_PARTNER_NOT_SUPPLIER | The source PO's partner is no longer designated as a supplier |
| PURCHASE_EMPTY_PURCHASE_ORDER_LINES | The source PO has no line items |
| PURCHASE_ITEM_NOT_FOUND | A referenced item no longer exists |
| PURCHASE_ITEM_NOT_ACTIVE | A referenced item has been deactivated |
| PURCHASE_ITEM_NOT_PURCHASABLE | A referenced item has no purchasing record |
| PURCHASE_INVALID_QUANTITY | A copied line item quantity is invalid |
| PURCHASE_INVALID_UNIT_PRICE | A copied line item unit price is invalid |
| PURCHASE_RECEIVING_SITE_NOT_FOUND | The source PO's receiving site no longer exists |
| PURCHASE_RECEIVING_SITE_REQUIRED | A line on the source PO requires a receiving site that is not set |
