feat(admin-ui, medusa): Improve fulfillment validation (#3541)
* validate that an inventory level exists as well * improve create-fulfillment handling in admin * pass along location id rather than inventory level id * add changeset * remove dependency
This commit is contained in:
@@ -168,7 +168,11 @@ export const updateInventoryAndReservations = async (
|
||||
items.map(({ item, quantity }) => ({ ...item, quantity } as LineItem)),
|
||||
locationId
|
||||
)
|
||||
})
|
||||
)
|
||||
|
||||
await Promise.all(
|
||||
fulfillments.map(async ({ items }) => {
|
||||
await Promise.all(
|
||||
items.map(async ({ item, quantity }) => {
|
||||
if (!item.variant_id) {
|
||||
|
||||
@@ -514,12 +514,19 @@ class ProductVariantInventoryService extends TransactionBaseService {
|
||||
for (const item of itemsToValidate) {
|
||||
const pvInventoryItems = await this.listByVariant(item.variant_id!)
|
||||
|
||||
const [inventoryLevels] =
|
||||
const [inventoryLevels, inventoryLevelCount] =
|
||||
await this.inventoryService_.listInventoryLevels({
|
||||
inventory_item_id: pvInventoryItems.map((i) => i.inventory_item_id),
|
||||
location_id: locationId,
|
||||
})
|
||||
|
||||
if (!inventoryLevelCount) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.NOT_ALLOWED,
|
||||
`Inventory item for ${item.title} not found at location`
|
||||
)
|
||||
}
|
||||
|
||||
const pviMap: Map<string, ProductVariantInventoryItem> = new Map(
|
||||
pvInventoryItems.map((pvi) => [pvi.inventory_item_id, pvi])
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user