# Outbound stocks

This guide explains the setup process for outbound stock tracking.

{% hint style="success" %}

## Prerequisites

* Picking must be done with the fulfillmenttools picking feature.
* Handover must be done with the fulfillmenttools handover feature.
  {% endhint %}

## Configuration

### Create an outbound storage location

An outbound storage location is required for items that have been picked and are ready for handover to a shipping provider. The defined location does not need to represent a physical storage space but should map the concept of outbound stock. This location can be created in the `Backoffice` or through the API.

The location must comply with the following requirements:

* `type` must be `BULK_STORAGE`.
* The stock at an outbound storage location is unavailable for orders and should not be picked or moved, except for handover. Therefore, it must have the following trait configuration:
  * `ACCESSIBLE: false`
  * `PICKABLE: false`
  * `OUTBOUND: true`
* `name`: A descriptive name, such as "Outgoing Goods", is recommended to clarify its function and prevent users from manually adjusting stock in this location.

Below is an example API call to create the storage location.

```http
POST https://{YOUR-TENANT-NAME}.api.fulfillmenttools.com/api/facilities/{facilityId}/storagelocations
```

```json
{
  "name": "Outgoing Goods",
  "tenantLocationId": "outbound-1",
  "type": "BULK_STORAGE",
  "scannableCodes": [],
  "runningSequences": [],
  "traitConfig": [
    {
      "trait": "ACCESSIBLE",
      "enabled": false
    },
    {
      "trait": "PICKABLE",
      "enabled": false
    },
    {
      "trait": "OUTBOUND",
      "enabled": true
    }
  ]
}
```

A successful request returns an `HTTP 201 Created` response containing the created storage location.

The `id` from the response of the created storage location is required for the next step.

### Enable the configuration

The `FacilityInventoryConfiguration` must be created or updated to enable outbound tracking. The example below assumes a `FacilityInventoryConfiguration` is already present. If not, use the `POST` endpoint. Ensure that previous settings in the configuration are not overwritten.

Configure the following fields in the `outboundStockConfiguration` object:

* `trackOutboundStock`: Activates or deactivates the feature without deleting previously defined settings.
* `locationRef`: References the `id` of the outbound storage location created in the previous step.
* `clearTrigger`: Specifies when the stock should be deleted in the respective facility.
  * `event`:
    * Use `pick-job-closed_event-v1` if the stock should be deleted after picking.
    * Use `handoverjob-handed-over_event-v1` if the stock should be deleted after being handed over to another party, such as a carrier.
  * `tagFilter`:
    * Can be configured to allow for further granularity.
    * Each entry in the `tagFilter` array represents a condition, and all conditions must be fulfilled.
      * Each value in the `allowedValues` array represents a possible value, one of which must be matched.
      * If the event is a pick job event, the conditions will be evaluated against the tag array in the pick job.
      * If the event is a handover job event, the conditions will be evaluated against the tag array in the handover job.

```http
PATCH https://{YOUR-TENANT-NAME}.api.fulfillmenttools.com/api/facilities/{facilityId}/configurations/inventory
```

```json
{
  "version": 2,
  "outboundStockConfiguration": {
    "trackOutboundStock": true,
    "locationRef": "<your location ref>",
    "clearTrigger": [
        {
            "event": "handoverjob-handed-over_event-v1"
        },
        {
            "event": "pick-job-closed_event-v1",
            "tagFilter": [
              {
                "tagId": "order-type",
                "allowedValues": [
                  "production"
                ]
              }
            ]
        }
    ]
  }
}
```

A successful request returns either an `HTTP 200 OK` or `HTTP 201 Created` response containing the updated or created configuration.

### Verifying the configuration

After these steps, outbound location tracking for the facility is enabled. To verify the setup, complete a pick job in this facility and observe the stock changes at the outbound location using the `stocks` endpoint.
