# Prepare Package Command

## <mark style="color:red;">Actors</mark>

* Akinon Order Management System (OMS)

## <mark style="color:red;">Domain Objects</mark>

* Packaging Order
* OMS Command (Packaging Order Command)

## <mark style="color:red;">Process</mark>

1. The OMS application copies orders from the Akinon Omnitron Application to itself to prepare delivery/distribution plans, generate packaging orders and transfer them to operation points.
2. The products in the order are distributed to the Packaging Orders by running the rules in the distribution scenarios designated by the brand.
3. Packaging Orders are transferred to the Akinon Instore App or the brand’s integrated software. (via Packaging Orders Webhooks)
4. Packaging orders assigned to the Store/Warehouse commence in the Waiting status.
5. The *PREPARE\_PACKAGE\_COMMAND* command is executed to prepare the products in the package. If there are missing products or replaceable products in the package, this command should be executed.
6. This command does three things at the same time:
   * If there are missing/defective products in the package, it marks these products as out-of-stock. The *DETECTED\_OUT\_OF\_STOCK\_ITEM* command must be added for this operation.
   * If there are replaceable products in the package, it replaces a product with an alternative product. The *REPLACE\_PRODUCT* command must be added for this operation.
   * For the remaining products in the package, it updates the barcode information. The *PKG\_STATE\_TRANSITION* command must be added for this operation.
7. When this command is executed, the status of the packaging order is updated to Preparing.
8. If the command is executed successfully, the API returns the package ID, package number, stock location ID and remaining package items.

## <mark style="color:red;">Command Parameters and Prerequisites</mark>

For each packaging order;

<table><thead><tr><th width="183.98046875">Parameter Name</th><th width="102.9765625">Parameter Type</th><th>Parameter Description</th><th>Requirement</th></tr></thead><tbody><tr><td>package</td><td>integer</td><td>The ID of the package</td><td>Mandatory</td></tr><tr><td>transition</td><td>integer</td><td>The ID of the command</td><td>Optional (if Slug is given)</td></tr><tr><td>slug</td><td>slug</td><td>Unique slug of the command</td><td>Optional (if Transition ID is given)</td></tr><tr><td>select_items_by_omnitron_id</td><td>boolean</td><td>Select items by Omnitron ID</td><td>Mandatory (It can be send as false)</td></tr><tr><td>replacement_products</td><td>list</td><td>List of replaceable products</td><td>Optional</td></tr><tr><td>create_manual_oos_package</td><td>boolean</td><td>Create manual OOS package</td><td>Mandatory (It can be send as false)</td></tr><tr><td>oos_package_items</td><td>list</td><td>ID's of the missing/defective package items</td><td>Optional</td></tr><tr><td>barcodes</td><td>list</td><td>Barcode values of the package items</td><td>Optional</td></tr><tr><td>denial_reason</td><td>integer</td><td>Denial reason ID</td><td>Optional</td></tr><tr><td>unit_weights</td><td>list</td><td>Unit Weight values of the package items</td><td>Optional</td></tr></tbody></table>

* This command can only be executed for packages that are in the following states:
  * Waiting (enum\_value: 100)

## <mark style="color:red;">`POST`</mark> <mark style="color:red;">**Prepare Package**</mark>

**Path:** `https://{customer_api_url}/api/v1/oms/packages/{package_id}/command/`

#### Request Body

```json
{
  "transition": 71,
  "input_parameters": {
    "select_items_by_omnitron_id": true,
    "replacement_products": [
      {
        "package_item": 282687,
        "new_product_sku": "10034"
      }
    ],
    "create_manual_oos_package": true,
    "oos_package_items": [
      282688
    ],
    "barcodes": [
      {
        "order_item": 2047,
        "barcode": "123"
      },
      {
        "order_item": 2046,
        "barcode": "123"
      },
      {
        "order_item": 2045,
        "barcode": "123"
      }
    ]
  }
}
```

#### Successful Response

Status Code: `200 OK`

After the successful execution of the command, the API returns following responses :

```json
{
  "id": 123,
  "number": "1234567891234567P3",
  "stock_location": 2,
  "packageitem_set": ["..."]
}
```
