# updateSalesOrder

## Overview

Updates a DRAFT sales order — changes the addresses, adds/patches/removes line items. Line edits are incremental: only the lines named in `addLines` / `updateLines` / `removeLineIds` are touched. The customer is not editable; pricing was resolved from the customer at create time, so a different customer means a new order. DRAFT-only enforcement is delegated to erp-kit's `sales.UpdateSalesOrder` command.

Input: `id`, `shippingAddress?`, `billingAddress?` (null clears either), `addLines?` — array of `{ itemId, quantity, unitPrice, unitId? }`, `updateLines?` — array of `{ lineId, itemId?, quantity?, unitPrice?, unitId? }`, `removeLineIds?`. A line that omits `unitId` defaults to the item's base unit, like createSalesOrder.

## Modules Commands Used

- [sales] UpdateSalesOrder

## Exception Handling

| Error Code | Description |
| --- | --- |
| SALES_SALES_ORDER_NOT_FOUND | The specified sales order does not exist |
| SALES_ORDER_NOT_EDITABLE | The sales order is not in DRAFT status and cannot be edited |
| SALES_LINE_NOT_FOUND | A referenced line does not exist on the sales order |
| SALES_EMPTY_ORDER_NOT_ALLOWED | The edit would leave the sales order with no lines |
| SALES_INVALID_ORDER_LINE | A line item is invalid (e.g., non-positive quantity or negative unit price) |
| SALES_ITEM_NOT_FOUND | A referenced item does not exist |
| SALES_ITEM_NOT_ACTIVE | A referenced item is not in active status |
| SALES_CROSS_COMPANY_REFERENCE | A referenced item belongs to a different company |
