feat(inventory,dashboard,types,core-flows,js-sdk,medusa): Improve inventory UX (#10630)
* feat(dashboard): Add UI for bulk editing inventory stock (#10556) * progress * cleanup types * add changeset * fix 0 values * format schema * add delete event and allow copy/pasting enabled for some fields * add response types * add tests * work on fixing setValue behaviour * cleanup toggle logic * add loading state * format schema * add support for bidirectional actions in DataGrid and update Checkbox and RadioGroup * update lock * lint * fix 404 * address feedback * update cursor on bidirectional select
This commit is contained in:
committed by
GitHub
parent
c5915451b8
commit
bc22b81cdf
@@ -11,7 +11,6 @@ export const createInventoryLevelsStep = createStep(
|
||||
createInventoryLevelsStepId,
|
||||
async (data: InventoryTypes.CreateInventoryLevelInput[], { container }) => {
|
||||
const service = container.resolve<IInventoryService>(Modules.INVENTORY)
|
||||
|
||||
const inventoryLevels = await service.createInventoryLevels(data)
|
||||
return new StepResponse(
|
||||
inventoryLevels,
|
||||
|
||||
@@ -13,10 +13,7 @@ export const updateInventoryLevelsStepId = "update-inventory-levels-step"
|
||||
*/
|
||||
export const updateInventoryLevelsStep = createStep(
|
||||
updateInventoryLevelsStepId,
|
||||
async (
|
||||
input: InventoryTypes.BulkUpdateInventoryLevelInput[],
|
||||
{ container }
|
||||
) => {
|
||||
async (input: InventoryTypes.UpdateInventoryLevelInput[], { container }) => {
|
||||
const inventoryService: IInventoryService = container.resolve(
|
||||
Modules.INVENTORY
|
||||
)
|
||||
@@ -54,7 +51,7 @@ export const updateInventoryLevelsStep = createStep(
|
||||
await inventoryService.updateInventoryLevels(
|
||||
dataBeforeUpdate.map((data) =>
|
||||
convertItemResponseToUpdateRequest(data, selects, relations)
|
||||
) as InventoryTypes.BulkUpdateInventoryLevelInput[]
|
||||
) as InventoryTypes.UpdateInventoryLevelInput[]
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import {
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
transform,
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { BatchWorkflowInput, InventoryTypes } from "@medusajs/types"
|
||||
import { createInventoryLevelsStep, updateInventoryLevelsStep } from "../steps"
|
||||
import { deleteInventoryLevelsWorkflow } from "./delete-inventory-levels"
|
||||
|
||||
export interface BatchInventoryItemLevelsWorkflowInput
|
||||
extends BatchWorkflowInput<
|
||||
InventoryTypes.CreateInventoryLevelInput,
|
||||
InventoryTypes.UpdateInventoryLevelInput
|
||||
> {
|
||||
/**
|
||||
* If true, the workflow will force deletion of the inventory levels, even
|
||||
* if they have a non-zero stocked quantity. It false, the workflow will
|
||||
* not delete the inventory levels if they have a non-zero stocked quantity.
|
||||
*
|
||||
* Inventory levels that have reserved or incoming items at the location
|
||||
* will not be deleted even if the force flag is set to true.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
force?: boolean
|
||||
}
|
||||
|
||||
export const batchInventoryItemLevelsWorkflowId =
|
||||
"batch-inventory-item-levels-workflow"
|
||||
|
||||
export const batchInventoryItemLevelsWorkflow = createWorkflow(
|
||||
batchInventoryItemLevelsWorkflowId,
|
||||
(input: WorkflowData<BatchInventoryItemLevelsWorkflowInput>) => {
|
||||
const { createInput, updateInput, deleteInput } = transform(
|
||||
input,
|
||||
(data) => {
|
||||
return {
|
||||
createInput: data.create || [],
|
||||
updateInput: data.update || [],
|
||||
deleteInput: {
|
||||
id: data.delete || [],
|
||||
force: data.force ?? false,
|
||||
},
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const res = parallelize(
|
||||
createInventoryLevelsStep(createInput),
|
||||
updateInventoryLevelsStep(updateInput),
|
||||
deleteInventoryLevelsWorkflow.runAsStep({
|
||||
input: deleteInput,
|
||||
})
|
||||
)
|
||||
|
||||
return new WorkflowResponse(
|
||||
transform({ res, input }, (data) => {
|
||||
return {
|
||||
created: data.res[0],
|
||||
updated: data.res[1],
|
||||
deleted: data.input.delete,
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
)
|
||||
@@ -1,3 +1,5 @@
|
||||
// TODO: Remove this workflow in a future release.
|
||||
|
||||
import { InventoryLevelDTO, InventoryTypes } from "@medusajs/framework/types"
|
||||
import {
|
||||
createWorkflow,
|
||||
@@ -17,6 +19,8 @@ export const bulkCreateDeleteLevelsWorkflowId =
|
||||
"bulk-create-delete-levels-workflow"
|
||||
/**
|
||||
* This workflow creates and deletes inventory levels.
|
||||
*
|
||||
* @deprecated Use `batchInventoryItemLevels` instead.
|
||||
*/
|
||||
export const bulkCreateDeleteLevelsWorkflow = createWorkflow(
|
||||
bulkCreateDeleteLevelsWorkflowId,
|
||||
|
||||
@@ -6,7 +6,10 @@ import {
|
||||
WorkflowResponse,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
import { FilterableInventoryLevelProps } from "@medusajs/framework/types"
|
||||
import {
|
||||
FilterableInventoryLevelProps,
|
||||
InventoryLevelDTO,
|
||||
} from "@medusajs/framework/types"
|
||||
import { deduplicate, MedusaError, Modules } from "@medusajs/framework/utils"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import { deleteEntitiesStep } from "../../common/steps/delete-entities"
|
||||
@@ -16,24 +19,52 @@ import { deleteEntitiesStep } from "../../common/steps/delete-entities"
|
||||
*/
|
||||
export const validateInventoryLevelsDelete = createStep(
|
||||
"validate-inventory-levels-delete",
|
||||
async function ({ inventoryLevels }: { inventoryLevels: any[] }) {
|
||||
const undeleteableItems = inventoryLevels.filter(
|
||||
(i) => i.reserved_quantity > 0 || i.stocked_quantity > 0
|
||||
async function ({
|
||||
inventoryLevels,
|
||||
force,
|
||||
}: {
|
||||
inventoryLevels: InventoryLevelDTO[]
|
||||
force?: boolean
|
||||
}) {
|
||||
const undeleteableDueToReservation = inventoryLevels.filter(
|
||||
(i) => i.reserved_quantity > 0 || i.incoming_quantity > 0
|
||||
)
|
||||
|
||||
if (undeleteableItems.length) {
|
||||
const stockLocationIds = deduplicate(
|
||||
undeleteableItems.map((item) => item.location_id)
|
||||
if (undeleteableDueToReservation.length) {
|
||||
const locationIds = deduplicate(
|
||||
undeleteableDueToReservation.map((item) => item.location_id)
|
||||
)
|
||||
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.NOT_ALLOWED,
|
||||
`Cannot remove Inventory Levels for ${stockLocationIds} because there are stocked or reserved items at the locations`
|
||||
`Cannot remove Inventory Levels for ${locationIds.join(
|
||||
", "
|
||||
)} because there are reserved or incoming items at the locations`
|
||||
)
|
||||
}
|
||||
|
||||
const undeleteableDueToStock = inventoryLevels.filter(
|
||||
(i) => !force && i.stocked_quantity > 0
|
||||
)
|
||||
|
||||
if (undeleteableDueToStock.length) {
|
||||
const locationIds = deduplicate(
|
||||
undeleteableDueToStock.map((item) => item.location_id)
|
||||
)
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.NOT_ALLOWED,
|
||||
`Cannot remove Inventory Levels for ${locationIds.join(
|
||||
", "
|
||||
)} because there are stocked items at the locations. Use force flag to delete anyway.`
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
export interface DeleteInventoryLevelsWorkflowInput
|
||||
extends FilterableInventoryLevelProps {
|
||||
force?: boolean
|
||||
}
|
||||
|
||||
export const deleteInventoryLevelsWorkflowId =
|
||||
"delete-inventory-levels-workflow"
|
||||
/**
|
||||
@@ -41,16 +72,25 @@ export const deleteInventoryLevelsWorkflowId =
|
||||
*/
|
||||
export const deleteInventoryLevelsWorkflow = createWorkflow(
|
||||
deleteInventoryLevelsWorkflowId,
|
||||
(input: WorkflowData<FilterableInventoryLevelProps>) => {
|
||||
(input: WorkflowData<DeleteInventoryLevelsWorkflowInput>) => {
|
||||
const { filters, force } = transform(input, (data) => {
|
||||
const { force, ...filters } = data
|
||||
|
||||
return {
|
||||
filters,
|
||||
force,
|
||||
}
|
||||
})
|
||||
|
||||
const inventoryLevels = useRemoteQueryStep({
|
||||
entry_point: "inventory_levels",
|
||||
fields: ["id", "stocked_quantity", "reserved_quantity", "location_id"],
|
||||
variables: {
|
||||
filters: input,
|
||||
filters: filters,
|
||||
},
|
||||
})
|
||||
|
||||
validateInventoryLevelsDelete({ inventoryLevels })
|
||||
validateInventoryLevelsDelete({ inventoryLevels, force })
|
||||
|
||||
const idsToDelete = transform({ inventoryLevels }, ({ inventoryLevels }) =>
|
||||
inventoryLevels.map((il) => il.id)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
export * from "./delete-inventory-items"
|
||||
export * from "./batch-inventory-item-levels"
|
||||
export * from "./bulk-create-delete-levels"
|
||||
export * from "./create-inventory-items"
|
||||
export * from "./create-inventory-levels"
|
||||
export * from "./update-inventory-items"
|
||||
export * from "./delete-inventory-items"
|
||||
export * from "./delete-inventory-levels"
|
||||
export * from "./update-inventory-items"
|
||||
export * from "./update-inventory-levels"
|
||||
export * from "./bulk-create-delete-levels"
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
import { updateInventoryLevelsStep } from "../steps/update-inventory-levels"
|
||||
|
||||
export interface UpdateInventoryLevelsWorkflowInput {
|
||||
updates: InventoryTypes.BulkUpdateInventoryLevelInput[]
|
||||
updates: InventoryTypes.UpdateInventoryLevelInput[]
|
||||
}
|
||||
export const updateInventoryLevelsWorkflowId =
|
||||
"update-inventory-levels-workflow"
|
||||
|
||||
@@ -15,15 +15,15 @@ export class InventoryItem {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method creates an inventory item. It sends a request to the
|
||||
* This method creates an inventory item. It sends a request to the
|
||||
* [Create Inventory Item](https://docs.medusajs.com/api/admin#inventory-items_postinventoryitems)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @param body - The inventory item's details.
|
||||
* @param query - Configure the fields to retrieve in the inventory item.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The inventory item's details.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.inventoryItem.create({
|
||||
* sku: "SHIRT"
|
||||
@@ -52,13 +52,13 @@ export class InventoryItem {
|
||||
* This method updates an inventory level. It sends a request to the
|
||||
* [Update Inventory Item](https://docs.medusajs.com/api/admin#inventory-items_postinventoryitemsid)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @param id - The inventory item's ID.
|
||||
* @param body - The data to update.
|
||||
* @param query - Configure the fields to retrieve in the inventory item.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The inventory item's details.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.inventoryItem.update("iitem_123", {
|
||||
* sku: "SHIRT"
|
||||
@@ -85,28 +85,28 @@ export class InventoryItem {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method retrieves a paginated list of inventory items. It sends a request to the
|
||||
* This method retrieves a paginated list of inventory items. It sends a request to the
|
||||
* [List Inventory Items](https://docs.medusajs.com/api/admin#inventory-items_getinventoryitems)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @param query - Filters and pagination configurations.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The paginated list of inventory items.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* To retrieve the list of inventory items:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.inventoryItem.list()
|
||||
* .then(({ inventory_items, count, limit, offset }) => {
|
||||
* console.log(inventory_items)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* To configure the pagination, pass the `limit` and `offset` query parameters.
|
||||
*
|
||||
*
|
||||
* For example, to retrieve only 10 items and skip 10 items:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.inventoryItem.list({
|
||||
* limit: 10,
|
||||
@@ -116,10 +116,10 @@ export class InventoryItem {
|
||||
* console.log(inventory_items)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
|
||||
* in each inventory item:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.inventoryItem.list({
|
||||
* fields: "id,*location_levels"
|
||||
@@ -128,7 +128,7 @@ export class InventoryItem {
|
||||
* console.log(inventory_items)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store#select-fields-and-relations).
|
||||
*/
|
||||
async list(
|
||||
@@ -145,26 +145,26 @@ export class InventoryItem {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method retrieves an inventory item by its ID. It sends a request to the
|
||||
* This method retrieves an inventory item by its ID. It sends a request to the
|
||||
* [Get Inventory Item](https://docs.medusajs.com/api/admin#inventory-items_getinventoryitemsid) API route.
|
||||
*
|
||||
*
|
||||
* @param id - The inventory item's ID.
|
||||
* @param query - Configure the fields to retrieve in the inventory item.
|
||||
* @param headers - Headers to pass in the request
|
||||
* @returns The inventory item's details.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* To retrieve an inventory item by its ID:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.inventoryItem.retrieve("iitem_123")
|
||||
* .then(({ inventory_item }) => {
|
||||
* console.log(inventory_item)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* To specify the fields and relations to retrieve:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.inventoryItem.retrieve("iitem_123", {
|
||||
* fields: "id,*location_levels"
|
||||
@@ -173,7 +173,7 @@ export class InventoryItem {
|
||||
* console.log(inventory_item)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store#select-fields-and-relations).
|
||||
*/
|
||||
async retrieve(id: string, query?: SelectParams, headers?: ClientHeaders) {
|
||||
@@ -190,11 +190,11 @@ export class InventoryItem {
|
||||
* This method deletes an inventory item. This sends a request to the
|
||||
* [Delete Inventory Item](https://docs.medusajs.com/api/admin#inventory-items_deleteinventoryitemsid)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @param id - The inventory item's ID.
|
||||
* @param headers - Headers to pass in the request
|
||||
* @returns The deletion's details.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.inventoryItem.delete("iitem_123")
|
||||
* .then(({ deleted }) => {
|
||||
@@ -215,26 +215,26 @@ export class InventoryItem {
|
||||
* This method retrieves a paginated list of inventory levels that belong to an inventory item.
|
||||
* It sends a request to the [List Inventory Items](https://docs.medusajs.com/api/admin#inventory-items_getinventoryitems)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @param id - The inventory item's ID.
|
||||
* @param query - Filters and pagination configurations.
|
||||
* @param headers - Headers to pass in the request.
|
||||
* @returns The paginated list of inventory levels.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* To retrieve the list of inventory levels:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.inventoryItem.listLevels("iitem_123")
|
||||
* .then(({ inventory_levels, count, limit, offset }) => {
|
||||
* console.log(inventory_levels)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* To configure the pagination, pass the `limit` and `offset` query parameters.
|
||||
*
|
||||
*
|
||||
* For example, to retrieve only 10 items and skip 10 items:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.inventoryItem.listLevels("iitem_123", {
|
||||
* limit: 10,
|
||||
@@ -244,10 +244,10 @@ export class InventoryItem {
|
||||
* console.log(inventory_levels)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* Using the `fields` query parameter, you can specify the fields and relations to retrieve
|
||||
* in each inventory level:
|
||||
*
|
||||
*
|
||||
* ```ts
|
||||
* sdk.admin.inventoryItem.listLevels("iitem_123", {
|
||||
* fields: "id,*inventory_item"
|
||||
@@ -256,7 +256,7 @@ export class InventoryItem {
|
||||
* console.log(inventory_levels)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
*
|
||||
* Learn more about the `fields` property in the [API reference](https://docs.medusajs.com/api/store#select-fields-and-relations).
|
||||
*/
|
||||
async listLevels(
|
||||
@@ -276,18 +276,18 @@ export class InventoryItem {
|
||||
/**
|
||||
* This method updates the inventory level of the specified inventory item and
|
||||
* stock location.
|
||||
*
|
||||
* This method sends a request to the
|
||||
*
|
||||
* This method sends a request to the
|
||||
* [Update Inventory Level](https://docs.medusajs.com/api/admin#inventory-items_postinventoryitemsidlocationlevelslocation_id)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @param id - The inventory item's ID.
|
||||
* @param locationId - The stock location's ID.
|
||||
* @param body - The details to update.
|
||||
* @param query - Configure the fields to retrieve in the inventory item.
|
||||
* @param headers - Headers to pass in the request
|
||||
* @returns The inventory item's details.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.inventoryItem.updateLevel(
|
||||
* "iitem_123",
|
||||
@@ -321,16 +321,16 @@ export class InventoryItem {
|
||||
/**
|
||||
* This method deletes an inventory level associated with an inventory item
|
||||
* and a stock location.
|
||||
*
|
||||
* This method sends a request to the
|
||||
*
|
||||
* This method sends a request to the
|
||||
* [Remove Inventory Level](https://docs.medusajs.com/api/admin#inventory-items_deleteinventoryitemsidlocationlevelslocation_id)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @param id - The inventory item's ID.
|
||||
* @param locationId - The stock location's ID.
|
||||
* @param headers - Headers to pass in the request
|
||||
* @returns The deletion's details.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.inventoryItem.deleteLevel(
|
||||
* "iitem_123",
|
||||
@@ -354,32 +354,34 @@ export class InventoryItem {
|
||||
* This method manages the inventory levels of an inventory item. It sends a request to the
|
||||
* [Manage Inventory Levels](https://docs.medusajs.com/api/admin#inventory-items_postinventoryitemsidlocationlevelsbatch)
|
||||
* API route.
|
||||
*
|
||||
*
|
||||
* @deprecated Use `batchInventoryItemLocationLevels` instead.
|
||||
*
|
||||
* @param id - The inventory item's ID.
|
||||
* @param body - The inventory levels to create or delete.
|
||||
* @param query - Configure the fields to retrieve in the inventory item.
|
||||
* @param headers - Headers to pass in the request
|
||||
* @returns The inventory item's details.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.inventoryItem.batchUpdateLevels("iitem_123", {
|
||||
* create: [{
|
||||
* location_id: "sloc_123",
|
||||
* stocked_quantity: 10
|
||||
* }],
|
||||
* delete: ["sloc_123"]
|
||||
* delete: ["ilvl_123"]
|
||||
* })
|
||||
* .then(({ inventory_item }) => {
|
||||
* console.log(inventory_item)
|
||||
* .then(({ created, updated, deleted }) => {
|
||||
* console.log(created, updated, deleted)
|
||||
* })
|
||||
*/
|
||||
async batchUpdateLevels(
|
||||
id: string,
|
||||
body: HttpTypes.AdminBatchUpdateInventoryLevelLocation,
|
||||
body: HttpTypes.AdminBatchInventoryItemLocationLevels,
|
||||
query?: SelectParams,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminInventoryItemResponse>(
|
||||
return await this.client.fetch<HttpTypes.AdminBatchInventoryItemLocationLevelsResponse>(
|
||||
`/admin/inventory-items/${id}/location-levels/batch`,
|
||||
{
|
||||
method: "POST",
|
||||
@@ -389,4 +391,75 @@ export class InventoryItem {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* This method manages the inventory levels of an inventory item. It sends a request to the
|
||||
* [Manage Inventory Levels](https://docs.medusajs.com/api/admin#inventory-items_postinventoryitemsidlocationlevelsbatch)
|
||||
* API route.
|
||||
*
|
||||
* @param id - The inventory item's ID.
|
||||
* @param body - The inventory levels to create, update or delete, and an optional `force` flag.
|
||||
* @param headers - Headers to pass in the request
|
||||
* @returns The inventory item's details.
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.inventoryItem.batchInventoryItemLocationLevels("iitem_123", {
|
||||
* create: [{
|
||||
* location_id: "sloc_123",
|
||||
* stocked_quantity: 10
|
||||
* }],
|
||||
* delete: ["ilvl_123"]
|
||||
* })
|
||||
* .then(({ created, updated, deleted }) => {
|
||||
* console.log(created, updated, deleted)
|
||||
* })
|
||||
*/
|
||||
async batchInventoryItemLocationLevels(
|
||||
id: string,
|
||||
body: HttpTypes.AdminBatchInventoryItemLocationLevels,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminBatchInventoryItemLocationLevelsResponse>(
|
||||
`/admin/inventory-items/${id}/location-levels/batch`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* This method manages the inventory levels of multiple inventory items.
|
||||
*
|
||||
* @param body - The inventory levels to create, update or delete, and an optional `force` flag.
|
||||
* @param headers - Headers to pass in the request
|
||||
* @returns The inventory item's details.
|
||||
*
|
||||
* @example
|
||||
* sdk.admin.inventoryItem.batchInventoryItemsLocationLevels({
|
||||
* create: [{
|
||||
* inventory_item_id: "iitem_123",
|
||||
* location_id: "sloc_123",
|
||||
* stocked_quantity: 10
|
||||
* }],
|
||||
* delete: ["ilvl_123"]
|
||||
* })
|
||||
* .then(({ created, updated, deleted }) => {
|
||||
* console.log(created, updated, deleted)
|
||||
* })
|
||||
*/
|
||||
async batchInventoryItemsLocationLevels(
|
||||
body: HttpTypes.AdminBatchInventoryItemsLocationLevels,
|
||||
headers?: ClientHeaders
|
||||
) {
|
||||
return await this.client.fetch<HttpTypes.AdminBatchInventoryItemsLocationLevelsResponse>(
|
||||
`/admin/inventory-items/location-levels/batch`,
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export interface AdminUpdateInventoryLevel {
|
||||
incoming_quantity?: number
|
||||
}
|
||||
|
||||
export interface AdminCreateInventoryLevel {
|
||||
export interface AdminBatchCreateInventoryItemLocationLevels {
|
||||
/**
|
||||
* The ID of the associated stock location.
|
||||
*/
|
||||
@@ -28,19 +28,85 @@ export interface AdminCreateInventoryLevel {
|
||||
incoming_quantity?: number
|
||||
}
|
||||
|
||||
export interface AdminBatchUpdateInventoryLevelLocation {
|
||||
export interface AdminBatchCreateInventoryItemLocationLevels {
|
||||
/**
|
||||
* The ID of the associated stock location.
|
||||
*/
|
||||
location_id: string
|
||||
/**
|
||||
* The associated inventory item's stocked quantity in the
|
||||
* associated stock location.
|
||||
*/
|
||||
stocked_quantity?: number
|
||||
/**
|
||||
* The associated inventory item's incoming quantity in the
|
||||
* associated stock location.
|
||||
*/
|
||||
incoming_quantity?: number
|
||||
}
|
||||
|
||||
export interface AdminBatchUpdateInventoryItemLocationLevels
|
||||
extends AdminBatchCreateInventoryItemLocationLevels {
|
||||
/**
|
||||
* The ID of the inventory level to update.
|
||||
*/
|
||||
id?: string
|
||||
}
|
||||
|
||||
export interface AdminBatchInventoryItemLocationLevels {
|
||||
/**
|
||||
* A list of inventory levels to update.
|
||||
*/
|
||||
update?: AdminBatchUpdateInventoryItemLocationLevels[]
|
||||
/**
|
||||
* A list of inventory levels to create.
|
||||
*/
|
||||
create?: AdminBatchCreateInventoryItemLocationLevels[]
|
||||
/**
|
||||
* A list of location IDs to
|
||||
* delete their associated inventory
|
||||
* delete their associated inventory
|
||||
* levels of the inventory item.
|
||||
*/
|
||||
delete?: string[]
|
||||
/**
|
||||
* @ignore
|
||||
* Whether to force the deletion of the inventory levels,
|
||||
* even if the the location has stocked quantity.
|
||||
*/
|
||||
update?: never // TODO - not implemented // AdminUpdateInventoryLevel[]
|
||||
/**
|
||||
* A list of inventory levels to create.
|
||||
*/
|
||||
create?: AdminCreateInventoryLevel[]
|
||||
force?: boolean
|
||||
}
|
||||
|
||||
export interface AdminBatchCreateInventoryItemsLocationLevels {
|
||||
/**
|
||||
* The ID of the associated stock location.
|
||||
*/
|
||||
location_id: string
|
||||
/**
|
||||
* The ID of the associated inventory item.
|
||||
*/
|
||||
inventory_item_id: string
|
||||
/**
|
||||
* The associated inventory item's stocked quantity in the
|
||||
* associated stock location.
|
||||
*/
|
||||
stocked_quantity?: number
|
||||
/**
|
||||
* The associated inventory item's incoming quantity in the
|
||||
* associated stock location.
|
||||
*/
|
||||
incoming_quantity?: number
|
||||
}
|
||||
|
||||
export interface AdminBatchUpdateInventoryItemsLocationLevels
|
||||
extends AdminBatchCreateInventoryItemsLocationLevels {
|
||||
/**
|
||||
* The ID of the inventory level to update.
|
||||
*/
|
||||
id?: string
|
||||
}
|
||||
|
||||
export interface AdminBatchInventoryItemsLocationLevels {
|
||||
create: AdminBatchCreateInventoryItemsLocationLevels[]
|
||||
update: AdminBatchUpdateInventoryItemsLocationLevels[]
|
||||
delete: string[]
|
||||
force?: boolean
|
||||
}
|
||||
|
||||
@@ -14,3 +14,21 @@ export type AdminInventoryLevelListResponse = PaginatedResponse<{
|
||||
*/
|
||||
inventory_levels: InventoryLevel[]
|
||||
}>
|
||||
|
||||
export interface AdminBatchInventoryItemLocationLevelsResponse {
|
||||
/**
|
||||
* The created inventory levels.
|
||||
*/
|
||||
created?: InventoryLevel[]
|
||||
/**
|
||||
* The updated inventory levels.
|
||||
*/
|
||||
updated?: InventoryLevel[]
|
||||
/**
|
||||
* The IDs of the deleted inventory levels.
|
||||
*/
|
||||
deleted?: string[]
|
||||
}
|
||||
|
||||
export interface AdminBatchInventoryItemsLocationLevelsResponse
|
||||
extends AdminBatchInventoryItemLocationLevelsResponse {}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { AdminCollection } from "../../collection"
|
||||
import { AdminInventoryItem } from "../../inventory"
|
||||
import { AdminPrice } from "../../pricing"
|
||||
import { AdminProductCategory } from "../../product-category"
|
||||
import { AdminProductTag } from "../../product-tag"
|
||||
@@ -13,6 +14,29 @@ import {
|
||||
ProductStatus,
|
||||
} from "../common"
|
||||
|
||||
export interface AdminProductVariantInventoryItemLink {
|
||||
/**
|
||||
* The ID of the pivot record.
|
||||
*/
|
||||
id: string
|
||||
/**
|
||||
* The ID of the variant.
|
||||
*/
|
||||
variant_id: string
|
||||
/**
|
||||
* The variant that the inventory item is linked to.
|
||||
*/
|
||||
variant?: AdminProductVariant
|
||||
/**
|
||||
* The ID of the inventory item.
|
||||
*/
|
||||
inventory_item_id: string
|
||||
/**
|
||||
* The inventory item that is linked to the variant.
|
||||
*/
|
||||
inventory?: AdminInventoryItem
|
||||
}
|
||||
|
||||
export interface AdminProductVariant extends BaseProductVariant {
|
||||
/**
|
||||
* The product variant's prices.
|
||||
@@ -26,6 +50,10 @@ export interface AdminProductVariant extends BaseProductVariant {
|
||||
* The product that this variant belongs to.
|
||||
*/
|
||||
product?: AdminProduct | null
|
||||
/**
|
||||
* The variant's inventory items.
|
||||
*/
|
||||
inventory_items?: AdminProductVariantInventoryItemLink[] | null
|
||||
}
|
||||
export interface AdminProductOption extends BaseProductOption {
|
||||
/**
|
||||
|
||||
@@ -26,9 +26,17 @@ export interface CreateInventoryLevelInput {
|
||||
*/
|
||||
export interface UpdateInventoryLevelInput {
|
||||
/**
|
||||
* id of the inventory level to update
|
||||
* ID of the inventory level to update
|
||||
*/
|
||||
id?: string
|
||||
/**
|
||||
* The ID of the associated inventory item.
|
||||
*/
|
||||
inventory_item_id: string
|
||||
/**
|
||||
* The ID of the associated location.
|
||||
*/
|
||||
location_id: string
|
||||
/**
|
||||
* The stocked quantity of the associated inventory item in the associated location.
|
||||
*/
|
||||
@@ -39,22 +47,6 @@ export interface UpdateInventoryLevelInput {
|
||||
incoming_quantity?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
* The attributes to update in an inventory level. The inventory level is identified by the IDs of its associated inventory item and location.
|
||||
*/
|
||||
export type BulkUpdateInventoryLevelInput = {
|
||||
/**
|
||||
* The ID of the associated inventory level.
|
||||
*/
|
||||
inventory_item_id: string
|
||||
/**
|
||||
* The ID of the associated location.
|
||||
*/
|
||||
location_id: string
|
||||
} & UpdateInventoryLevelInput
|
||||
|
||||
export type BulkAdjustInventoryLevelInput = {
|
||||
/**
|
||||
* The ID of the associated inventory level.
|
||||
@@ -69,4 +61,4 @@ export type BulkAdjustInventoryLevelInput = {
|
||||
* The quantity to adjust the inventory level by.
|
||||
*/
|
||||
adjustment: BigNumberInput
|
||||
} & UpdateInventoryLevelInput
|
||||
}
|
||||
|
||||
@@ -13,11 +13,11 @@ import {
|
||||
ReservationItemDTO,
|
||||
} from "./common"
|
||||
import {
|
||||
BulkUpdateInventoryLevelInput,
|
||||
CreateInventoryItemInput,
|
||||
CreateInventoryLevelInput,
|
||||
CreateReservationItemInput,
|
||||
UpdateInventoryItemInput,
|
||||
UpdateInventoryLevelInput,
|
||||
UpdateReservationItemInput,
|
||||
} from "./mutations"
|
||||
|
||||
@@ -610,7 +610,7 @@ export interface IInventoryService extends IModuleService {
|
||||
/**
|
||||
* This method updates existing inventory levels.
|
||||
*
|
||||
* @param {BulkUpdateInventoryLevelInput[]} updates - The list of The attributes to update in an inventory level. The inventory level is identified by the IDs of its associated inventory item and location.
|
||||
* @param {UpdateInventoryLevelInput[]} updates - The list of The attributes to update in an inventory level. The inventory level is identified by the IDs of its associated inventory item and location.
|
||||
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<InventoryLevelDTO[]>} The updated inventory levels.
|
||||
*
|
||||
@@ -626,14 +626,14 @@ export interface IInventoryService extends IModuleService {
|
||||
* ])
|
||||
*/
|
||||
updateInventoryLevels(
|
||||
updates: BulkUpdateInventoryLevelInput[],
|
||||
updates: UpdateInventoryLevelInput[],
|
||||
context?: Context
|
||||
): Promise<InventoryLevelDTO[]>
|
||||
|
||||
/**
|
||||
* This method updates an existing inventory level.
|
||||
*
|
||||
* @param {BulkUpdateInventoryLevelInput} updates - The attributes to update in an inventory level. The inventory level is identified by the IDs of its associated inventory item and location.
|
||||
* @param {UpdateInventoryLevelInput} updates - The attributes to update in an inventory level. The inventory level is identified by the IDs of its associated inventory item and location.
|
||||
* @param {Context} context - A context used to share resources, such as transaction manager, between the application and the module.
|
||||
* @returns {Promise<InventoryLevelDTO>} The updated inventory level.
|
||||
*
|
||||
@@ -646,7 +646,7 @@ export interface IInventoryService extends IModuleService {
|
||||
* })
|
||||
*/
|
||||
updateInventoryLevels(
|
||||
updates: BulkUpdateInventoryLevelInput,
|
||||
updates: UpdateInventoryLevelInput,
|
||||
context?: Context
|
||||
): Promise<InventoryLevelDTO>
|
||||
|
||||
@@ -1058,7 +1058,7 @@ export interface IInventoryService extends IModuleService {
|
||||
): Promise<InventoryLevelDTO[]>
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param {string} inventoryItemId - The inventory item's ID.
|
||||
* @param {string} locationId - The location's ID.
|
||||
* @param {number} adjustment - the adjustment to make to the quantity.
|
||||
|
||||
Reference in New Issue
Block a user