|
1
|
--- |
|
2
|
tags: |
|
3
|
- inventory |
|
4
|
- order |
|
5
|
- fulfillment |
|
6
|
- concept |
|
7
|
products: |
|
8
|
- inventory |
|
9
|
- order |
|
10
|
- fulfillment |
|
11
|
--- |
|
12
|
|
|
13
|
export const metadata = { |
|
14
|
title: `Reservations Lifecycle`, |
|
15
|
} |
|
16
|
|
|
17
|
# {metadata.title} |
|
18
|
|
|
19
|
In this guide, you'll learn about the lifecycle of a reservation in Medusa: when Medusa creates a reservation, how a reservation affects available stock, and when Medusa releases or deletes a reservation. |
|
20
|
|
|
21
|
## What is a Reservation? |
|
22
|
|
|
23
|
A reservation, represented by the [ReservationItem data model](/references/inventory-next/models/ReservationItem), is a reserved quantity of an inventory item in a location. A reservation holds stock for a purchase that isn't fulfilled yet. |
|
24
|
|
|
25
|
A reservation affects the [InventoryLevel](../concepts/page.mdx#inventorylevel) of the reserved inventory item in the associated location: |
|
26
|
|
|
27
|
- Its `reserved_quantity` increases by the reserved amount. |
|
28
|
- Its `stocked_quantity` stays the same. The reserved quantity is still physically in stock, but it's unavailable when Medusa checks whether an item can be purchased. |
|
29
|
|
|
30
|
So, the available quantity of an inventory item in a location is its `stocked_quantity` minus its `reserved_quantity`. |
|
31
|
|
|
32
|
<Note> |
|
33
|
|
|
34
|
Medusa only manages reservations for inventory items whose variants have `manage_inventory` enabled. Variants with `manage_inventory` disabled don't have reservations, and Medusa doesn't track their stock. |
|
35
|
|
|
36
|
</Note> |
|
37
|
|
|
38
|
--- |
|
39
|
|
|
40
|
## When Medusa Creates a Reservation |
|
41
|
|
|
42
|
### Order Placement |
|
43
|
|
|
44
|
Medusa creates a reservation for each of the order's inventory items when an order is placed by completing a cart. This is implemented in the [completeCartWorkflow](/references/medusa-workflows/completeCartWorkflow). |
|
45
|
|
|
46
|
The reservation is created in the location associated with the order's sales channel, and its quantity is the ordered quantity. |
|
47
|
|
|
48
|
<Note> |
|
49
|
|
|
50
|
Some workflows that create an order, such as the [createOrderWorkflow](/references/medusa-workflows/createOrderWorkflow), only check that there's sufficient stock without creating a reservation. If you create an order with one of these workflows, the [createOrderFulfillmentWorkflow](/references/medusa-workflows/createOrderFulfillmentWorkflow) throws an error for items whose variants have `manage_inventory` enabled, since they don't have an associated reservation. Create the reservations manually before fulfilling the order, as explained in the next section. |
|
51
|
|
|
52
|
</Note> |
|
53
|
|
|
54
|
### Custom Reservations |
|
55
|
|
|
56
|
You can also create a reservation for custom use cases, such as reserving stock for an offline sale. Use the [createReservationsWorkflow](/references/medusa-workflows/createReservationsWorkflow) to create one or more reservations. |
|
57
|
|
|
58
|
To associate a reservation with an order's item so that the fulfillment flow can find it, set the reservation's `line_item_id` to the order item's ID. |
|
59
|
|
|
60
|
--- |
|
61
|
|
|
62
|
## When Medusa Releases a Reservation |
|
63
|
|
|
64
|
A reservation is temporary. Medusa releases the reservation, making the quantity available again, in the following cases. |
|
65
|
|
|
66
|
### Order Fulfillment |
|
67
|
|
|
68
|
When an order's item is fulfilled, Medusa performs the following for each of the item's inventory items, as implemented in the [createOrderFulfillmentWorkflow](/references/medusa-workflows/createOrderFulfillmentWorkflow): |
|
69
|
|
|
70
|
- Subtracts the fulfilled quantity from the `stocked_quantity` of the inventory level. |
|
71
|
- Decreases the `reserved_quantity` of the inventory level by the fulfilled quantity. |
|
72
|
- Deletes the reservation if its full quantity is fulfilled, or decreases the reservation's quantity if only part of it is fulfilled. |
|
73
|
|
|
74
|
So, fulfillment turns reserved stock into consumed stock: the quantity leaves both the stocked and reserved counts. |
|
75
|
|
|
76
|
<Note title="Fulfillment provider"> |
|
77
|
|
|
78
|
These inventory changes are managed by Medusa's core workflow, independent of the fulfillment provider. The fulfillment provider handles the shipping side of the fulfillment, such as creating a shipping label, but it doesn't affect how Medusa decrements stock or deletes reservations. So, the stock changes happen the same way regardless of the fulfillment provider you use. |
|
79
|
|
|
80
|
</Note> |
|
81
|
|
|
82
|
### Order or Item Cancellation |
|
83
|
|
|
84
|
When an order or its items are canceled before fulfillment, Medusa deletes the associated reservations. The reserved quantity becomes available again for other purchases. |
|
85
|
|
|
86
|
If a fulfillment is canceled, Medusa restores the reservations that were released when the fulfillment was created. |
|
87
|
|
|
88
|
### Custom Deletion |
|
89
|
|
|
90
|
You can also delete reservations manually, such as when a custom reservation is no longer needed. Use the [deleteReservationsWorkflow](/references/medusa-workflows/deleteReservationsWorkflow) to delete one or more reservations. |
|
91
|
|
|
92
|
--- |
|
93
|
|
|
94
|
## Reservations for Inventory Kits |
|
95
|
|
|
96
|
A variant can be linked to multiple inventory items, forming an [inventory kit](../inventory-kit/page.mdx). This is useful for use cases like multi-part or bundled products. |
|
97
|
|
|
98
|
When a variant has an inventory kit, Medusa creates a reservation for each of the variant's inventory items. The reserved quantity of each inventory item is the ordered quantity multiplied by the inventory item's `required_quantity`. |
|
99
|
|
|
100
|
For example, if a bicycle variant requires two wheel inventory items, ordering one bicycle reserves two units of the wheel inventory item. |
|
101
|
|
|
102
|
The same lifecycle applies to each reservation in the kit: Medusa releases every reservation of the kit when the item is fulfilled or canceled. |
|
103
|
|
|
104
|
<Note> |
|
105
|
|
|
106
|
Since inventory items can be shared across variants and products, a reservation on a shared inventory item reduces the available quantity for all variants that use that inventory item. |
|
107
|
|
|
108
|
</Note> |