# createSalesOrder

## Overview

Creates a new sales order (受注) in DRAFT status with a customer, order date, shipping address, and priced line items. The `companyId` is taken from the customer, and the header currency is that company's `baseCurrencyId`. Thin wrapper over the native `sales` create command.

Input: `customerAccountId`, `orderDate?` (default today), `shippingAddress?`, `billingAddress?`, `lines` — array of `{ itemId, quantity (float), unitPrice (float), unitId? }`. When a line omits `unitId`, it defaults to the item's base unit (`Item.unitId`), so every order line carries a unit — required later to raise a customer invoice from the order.

## Modules Commands Used

- [sales] CreateSalesOrder

## Exception Handling

| Error Code | Description |
| --- | --- |
| SALES_COMPANY_NOT_FOUND | The customer's company does not exist |
| SALES_CURRENCY_MISMATCH | The currency is not the company's base currency |
| SALES_CUSTOMER_NOT_FOUND | The specified customer does not exist |
| SALES_CUSTOMER_NOT_ACTIVE | The specified customer is not in active status |
| SALES_CUSTOMER_ROLE_REQUIRED | The specified partner does not hold the CUSTOMER role |
| SALES_CROSS_COMPANY_REFERENCE | A referenced entity belongs to a different company than the customer |
| SALES_INVALID_ORDER_LINE | A line item is invalid (e.g., non-positive quantity or unit price) |
| SALES_ITEM_NOT_FOUND | A referenced item does not exist |
| SALES_ITEM_NOT_ACTIVE | A referenced item is not in active status |
