feat(core-flows,dashboard,medusa): fixes set of tiny bugs in claims flow (#8551)
* feat(types,dashboard): ability to set shipping methods for claim * chore: fix a bunch of stuff * chore: update comment
This commit is contained in:
1 parent
6ffe85aa3d
commit
dd4147314f
9 files changed
+238
-26
No files matched your search
@@ -19,6 +19,7 @@ medusaIntegrationTestRunner({
|
|||||||
let baseClaim
|
let baseClaim
|
||||||
let order, order2
|
let order, order2
|
||||||
let returnShippingOption
|
let returnShippingOption
|
||||||
|
let outboundShippingOption
|
||||||
let shippingProfile
|
let shippingProfile
|
||||||
let fulfillmentSet
|
let fulfillmentSet
|
||||||
let returnReason
|
let returnReason
|
||||||
@@ -348,6 +349,37 @@ medusaIntegrationTestRunner({
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const outboundShippingOptionPayload = {
|
||||||
|
name: "Oubound shipping",
|
||||||
|
service_zone_id: fulfillmentSet.service_zones[0].id,
|
||||||
|
shipping_profile_id: shippingProfile.id,
|
||||||
|
provider_id: shippingProviderId,
|
||||||
|
price_type: "flat",
|
||||||
|
type: {
|
||||||
|
label: "Test type",
|
||||||
|
description: "Test description",
|
||||||
|
code: "test-code",
|
||||||
|
},
|
||||||
|
prices: [
|
||||||
|
{
|
||||||
|
currency_code: "usd",
|
||||||
|
amount: 1000,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
operator: RuleOperator.EQ,
|
||||||
|
attribute: "is_return",
|
||||||
|
value: "false",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
operator: RuleOperator.EQ,
|
||||||
|
attribute: "enabled_in_store",
|
||||||
|
value: "true",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
returnShippingOption = (
|
returnShippingOption = (
|
||||||
await api.post(
|
await api.post(
|
||||||
"/admin/shipping-options",
|
"/admin/shipping-options",
|
||||||
@@ -356,6 +388,14 @@ medusaIntegrationTestRunner({
|
|||||||
)
|
)
|
||||||
).data.shipping_option
|
).data.shipping_option
|
||||||
|
|
||||||
|
outboundShippingOption = (
|
||||||
|
await api.post(
|
||||||
|
"/admin/shipping-options",
|
||||||
|
outboundShippingOptionPayload,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
).data.shipping_option
|
||||||
|
|
||||||
item = order.items[0]
|
item = order.items[0]
|
||||||
|
|
||||||
await api.post(
|
await api.post(
|
||||||
@@ -411,30 +451,69 @@ medusaIntegrationTestRunner({
|
|||||||
const claimId2 = r2.data.claim.id
|
const claimId2 = r2.data.claim.id
|
||||||
const item2 = order2.items[0]
|
const item2 = order2.items[0]
|
||||||
|
|
||||||
await api.post(
|
const {
|
||||||
|
data: {
|
||||||
|
order_preview: {
|
||||||
|
items: [previewItem],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} = await api.post(
|
||||||
`/admin/claims/${claimId2}/inbound/items`,
|
`/admin/claims/${claimId2}/inbound/items`,
|
||||||
|
{ items: [{ id: item2.id, quantity: 1 }] },
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
// Delete & recreate again to ensure it works for both delete and create
|
||||||
|
await api.delete(
|
||||||
|
`/admin/claims/${claimId2}/inbound/items/${previewItem.actions[0].id}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: { return: returnData },
|
||||||
|
} = await api.post(
|
||||||
|
`/admin/claims/${claimId2}/inbound/items`,
|
||||||
|
{ items: [{ id: item2.id, quantity: 1 }] },
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
await api.post(
|
||||||
|
`/admin/returns/${returnData.id}`,
|
||||||
{
|
{
|
||||||
items: [
|
location_id: location.id,
|
||||||
{
|
no_notification: true,
|
||||||
id: item2.id,
|
|
||||||
quantity: 1,
|
|
||||||
},
|
},
|
||||||
],
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: {
|
||||||
|
order_preview: { shipping_methods: inboundShippingMethods },
|
||||||
},
|
},
|
||||||
|
} = await api.post(
|
||||||
|
`/admin/claims/${claimId2}/inbound/shipping-method`,
|
||||||
|
{ shipping_option_id: returnShippingOption.id },
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
const inboundShippingMethod = inboundShippingMethods.find(
|
||||||
|
(m) => m.shipping_option_id == returnShippingOption.id
|
||||||
|
)
|
||||||
|
|
||||||
|
// Delete & recreate again to ensure it works for both delete and create
|
||||||
|
await api.delete(
|
||||||
|
`/admin/claims/${claimId2}/inbound/shipping-method/${inboundShippingMethod.actions[0].id}`,
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
await api.post(
|
await api.post(
|
||||||
`/admin/claims/${claimId2}/inbound/shipping-method`,
|
`/admin/claims/${claimId2}/inbound/shipping-method`,
|
||||||
{
|
{ shipping_option_id: returnShippingOption.id },
|
||||||
shipping_option_id: returnShippingOption.id,
|
|
||||||
},
|
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
await api.post(`/admin/claims/${claimId2}/request`, {}, adminHeaders)
|
await api.post(`/admin/claims/${claimId2}/request`, {}, adminHeaders)
|
||||||
|
|
||||||
const claimId = baseClaim.id
|
const claimId = baseClaim.id
|
||||||
|
|
||||||
const item = order.items[0]
|
const item = order.items[0]
|
||||||
|
|
||||||
let result = await api.post(
|
let result = await api.post(
|
||||||
@@ -453,9 +532,33 @@ medusaIntegrationTestRunner({
|
|||||||
|
|
||||||
await api.post(
|
await api.post(
|
||||||
`/admin/claims/${claimId}/inbound/shipping-method`,
|
`/admin/claims/${claimId}/inbound/shipping-method`,
|
||||||
{
|
{ shipping_option_id: returnShippingOption.id },
|
||||||
shipping_option_id: returnShippingOption.id,
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: {
|
||||||
|
order_preview: { shipping_methods: outboundShippingMethods },
|
||||||
},
|
},
|
||||||
|
} = await api.post(
|
||||||
|
`/admin/claims/${claimId}/outbound/shipping-method`,
|
||||||
|
{ shipping_option_id: outboundShippingOption.id },
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
const outboundShippingMethod = outboundShippingMethods.find(
|
||||||
|
(m) => m.shipping_option_id == outboundShippingOption.id
|
||||||
|
)
|
||||||
|
|
||||||
|
// Delete & recreate again to ensure it works for both delete and create
|
||||||
|
await api.delete(
|
||||||
|
`/admin/claims/${claimId}/outbound/shipping-method/${outboundShippingMethod.actions[0].id}`,
|
||||||
|
adminHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
await api.post(
|
||||||
|
`/admin/claims/${claimId}/outbound/shipping-method`,
|
||||||
|
{ shipping_option_id: outboundShippingOption.id },
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -486,8 +486,9 @@ export const useDeleteClaimOutboundShipping = (
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useRequestClaim = (
|
export const useClaimConfirmRequest = (
|
||||||
id: string,
|
id: string,
|
||||||
|
orderId: string,
|
||||||
options?: UseMutationOptions<
|
options?: UseMutationOptions<
|
||||||
HttpTypes.AdminClaimResponse,
|
HttpTypes.AdminClaimResponse,
|
||||||
Error,
|
Error,
|
||||||
|
|||||||
+4
-2
@@ -41,6 +41,7 @@ import {
|
|||||||
useAddClaimInboundItems,
|
useAddClaimInboundItems,
|
||||||
useAddClaimInboundShipping,
|
useAddClaimInboundShipping,
|
||||||
useCancelClaimRequest,
|
useCancelClaimRequest,
|
||||||
|
useClaimConfirmRequest,
|
||||||
useDeleteClaimInboundShipping,
|
useDeleteClaimInboundShipping,
|
||||||
useRemoveClaimInboundItem,
|
useRemoveClaimInboundItem,
|
||||||
useUpdateClaimInboundItem,
|
useUpdateClaimInboundItem,
|
||||||
@@ -86,7 +87,8 @@ export const ClaimCreateForm = ({
|
|||||||
* MUTATIONS
|
* MUTATIONS
|
||||||
*/
|
*/
|
||||||
// TODO: implement confirm claim request
|
// TODO: implement confirm claim request
|
||||||
const { mutateAsync: confirmClaimRequest, isPending: isConfirming } = {} // useConfirmClaimRequest(claim.id, order.id)
|
const { mutateAsync: confirmClaimRequest, isPending: isConfirming } =
|
||||||
|
useClaimConfirmRequest(claim.id, order.id)
|
||||||
|
|
||||||
const { mutateAsync: cancelClaimRequest, isPending: isCanceling } =
|
const { mutateAsync: cancelClaimRequest, isPending: isCanceling } =
|
||||||
useCancelClaimRequest(claim.id, order.id)
|
useCancelClaimRequest(claim.id, order.id)
|
||||||
@@ -94,7 +96,7 @@ export const ClaimCreateForm = ({
|
|||||||
// TODO: implement update claim request
|
// TODO: implement update claim request
|
||||||
|
|
||||||
const { mutateAsync: updateReturn, isPending: isUpdating } = useUpdateReturn(
|
const { mutateAsync: updateReturn, isPending: isUpdating } = useUpdateReturn(
|
||||||
claim.return_id!,
|
preview?.order_change?.return_id!,
|
||||||
order.id
|
order.id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { IOrderModuleService, UpdateOrderChangeDTO } from "@medusajs/types"
|
||||||
|
import {
|
||||||
|
ModuleRegistrationName,
|
||||||
|
getSelectsAndRelationsFromObjectArray,
|
||||||
|
} from "@medusajs/utils"
|
||||||
|
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||||
|
|
||||||
|
export const updateOrderChangesStepId = "update-order-shopping-methods"
|
||||||
|
/**
|
||||||
|
* This step updates order change.
|
||||||
|
*/
|
||||||
|
export const updateOrderChangesStep = createStep(
|
||||||
|
updateOrderChangesStepId,
|
||||||
|
async (data: UpdateOrderChangeDTO[], { container }) => {
|
||||||
|
const service = container.resolve<IOrderModuleService>(
|
||||||
|
ModuleRegistrationName.ORDER
|
||||||
|
)
|
||||||
|
|
||||||
|
const { selects, relations } = getSelectsAndRelationsFromObjectArray(data, {
|
||||||
|
objectFields: ["metadata"],
|
||||||
|
})
|
||||||
|
|
||||||
|
const dataBeforeUpdate = await service.listOrderChanges(
|
||||||
|
{ id: data.map((d) => d.id) },
|
||||||
|
{ relations, select: selects }
|
||||||
|
)
|
||||||
|
|
||||||
|
const updated = await service.updateOrderChanges(data)
|
||||||
|
|
||||||
|
return new StepResponse(updated, dataBeforeUpdate)
|
||||||
|
},
|
||||||
|
async (dataBeforeUpdate, { container }) => {
|
||||||
|
if (!dataBeforeUpdate?.length) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const service = container.resolve<IOrderModuleService>(
|
||||||
|
ModuleRegistrationName.ORDER
|
||||||
|
)
|
||||||
|
|
||||||
|
await service.updateOrderChanges(dataBeforeUpdate as UpdateOrderChangeDTO[])
|
||||||
|
}
|
||||||
|
)
|
||||||
@@ -10,7 +10,7 @@ import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
|||||||
|
|
||||||
export const updateOrderShippingMethodsStepId = "update-order-shopping-methods"
|
export const updateOrderShippingMethodsStepId = "update-order-shopping-methods"
|
||||||
/**
|
/**
|
||||||
* This step updats order shipping methods.
|
* This step updates order shipping methods.
|
||||||
*/
|
*/
|
||||||
export const updateOrderShippingMethodsStep = createStep(
|
export const updateOrderShippingMethodsStep = createStep(
|
||||||
updateOrderShippingMethodsStepId,
|
updateOrderShippingMethodsStepId,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import { updateOrderClaimsStep } from "../../steps/claim/update-order-claims"
|
|||||||
import { createOrderChangeActionsStep } from "../../steps/create-order-change-actions"
|
import { createOrderChangeActionsStep } from "../../steps/create-order-change-actions"
|
||||||
import { previewOrderChangeStep } from "../../steps/preview-order-change"
|
import { previewOrderChangeStep } from "../../steps/preview-order-change"
|
||||||
import { createReturnsStep } from "../../steps/return/create-returns"
|
import { createReturnsStep } from "../../steps/return/create-returns"
|
||||||
|
import { updateOrderChangesStep } from "../../steps/update-order-changes"
|
||||||
import {
|
import {
|
||||||
throwIfIsCancelled,
|
throwIfIsCancelled,
|
||||||
throwIfItemsDoesNotExistsInOrder,
|
throwIfItemsDoesNotExistsInOrder,
|
||||||
@@ -121,6 +122,17 @@ export const orderClaimRequestItemReturnWorkflow = createWorkflow(
|
|||||||
name: "order-change-query",
|
name: "order-change-query",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
when({ createdReturn }, ({ createdReturn }) => {
|
||||||
|
return !!createdReturn?.length
|
||||||
|
}).then(() => {
|
||||||
|
updateOrderChangesStep([
|
||||||
|
{
|
||||||
|
id: orderChange.id,
|
||||||
|
return_id: createdReturn?.[0]?.id,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
orderClaimRequestItemReturnValidationStep({
|
orderClaimRequestItemReturnValidationStep({
|
||||||
order,
|
order,
|
||||||
items: input.items,
|
items: input.items,
|
||||||
|
|||||||
@@ -84,11 +84,11 @@ function prepareFulfillmentData({
|
|||||||
order.items!.map((i) => [i.id, i])
|
order.items!.map((i) => [i.id, i])
|
||||||
)
|
)
|
||||||
const fulfillmentItems = items.map((i) => {
|
const fulfillmentItems = items.map((i) => {
|
||||||
const orderItem = orderItemsMap.get(i.item_id) ?? i.item
|
const orderItem = orderItemsMap.get(i.id) ?? i.item
|
||||||
|
|
||||||
return {
|
return {
|
||||||
line_item_id: i.item_id,
|
line_item_id: i.item_id,
|
||||||
quantity: !isReturn ? i.quantity : undefined,
|
quantity: i.quantity,
|
||||||
return_quantity: isReturn ? i.quantity : undefined,
|
|
||||||
title: orderItem.variant_title ?? orderItem.title,
|
title: orderItem.variant_title ?? orderItem.title,
|
||||||
sku: orderItem.variant_sku || "",
|
sku: orderItem.variant_sku || "",
|
||||||
barcode: orderItem.variant_barcode || "",
|
barcode: orderItem.variant_barcode || "",
|
||||||
@@ -160,7 +160,7 @@ function extractShippingOption({ orderPreview, orderClaim, returnId }) {
|
|||||||
|
|
||||||
for (const action of modifiedShippingMethod_.actions) {
|
for (const action of modifiedShippingMethod_.actions) {
|
||||||
if (action.action === ChangeActionType.SHIPPING_ADD) {
|
if (action.action === ChangeActionType.SHIPPING_ADD) {
|
||||||
if (action.return_id === returnId) {
|
if (action.return?.id === returnId) {
|
||||||
returnShippingMethod = shippingMethod
|
returnShippingMethod = shippingMethod
|
||||||
} else if (action.claim_id === orderClaim.id) {
|
} else if (action.claim_id === orderClaim.id) {
|
||||||
claimShippingMethod = shippingMethod
|
claimShippingMethod = shippingMethod
|
||||||
@@ -181,7 +181,9 @@ export const confirmClaimRequestWorkflowId = "confirm-claim-request"
|
|||||||
*/
|
*/
|
||||||
export const confirmClaimRequestWorkflow = createWorkflow(
|
export const confirmClaimRequestWorkflow = createWorkflow(
|
||||||
confirmClaimRequestWorkflowId,
|
confirmClaimRequestWorkflowId,
|
||||||
function (input: ConfirmClaimRequestWorkflowInput): WorkflowResponse<OrderDTO> {
|
function (
|
||||||
|
input: ConfirmClaimRequestWorkflowInput
|
||||||
|
): WorkflowResponse<OrderDTO> {
|
||||||
const orderClaim: OrderClaimDTO = useRemoteQueryStep({
|
const orderClaim: OrderClaimDTO = useRemoteQueryStep({
|
||||||
entry_point: "order_claim",
|
entry_point: "order_claim",
|
||||||
fields: ["id", "status", "order_id", "canceled_at"],
|
fields: ["id", "status", "order_id", "canceled_at"],
|
||||||
@@ -196,11 +198,8 @@ export const confirmClaimRequestWorkflow = createWorkflow(
|
|||||||
"id",
|
"id",
|
||||||
"version",
|
"version",
|
||||||
"canceled_at",
|
"canceled_at",
|
||||||
"items.id",
|
"items.*",
|
||||||
"items.title",
|
"items.item.id",
|
||||||
"items.variant_title",
|
|
||||||
"items.variant_sku",
|
|
||||||
"items.variant_barcode",
|
|
||||||
"shipping_address.*",
|
"shipping_address.*",
|
||||||
],
|
],
|
||||||
variables: { id: orderClaim.order_id },
|
variables: { id: orderClaim.order_id },
|
||||||
|
|||||||
@@ -922,6 +922,11 @@ export interface UpdateOrderChangeDTO {
|
|||||||
*/
|
*/
|
||||||
description?: string
|
description?: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The associated return's ID.
|
||||||
|
*/
|
||||||
|
return_id?: string | null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The internal note of the order change.
|
* The internal note of the order change.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { Context } from "../shared-context"
|
|||||||
import {
|
import {
|
||||||
FilterableOrderAddressProps,
|
FilterableOrderAddressProps,
|
||||||
FilterableOrderChangeActionProps,
|
FilterableOrderChangeActionProps,
|
||||||
|
FilterableOrderChangeProps,
|
||||||
FilterableOrderClaimProps,
|
FilterableOrderClaimProps,
|
||||||
FilterableOrderExchangeProps,
|
FilterableOrderExchangeProps,
|
||||||
FilterableOrderLineItemAdjustmentProps,
|
FilterableOrderLineItemAdjustmentProps,
|
||||||
@@ -2254,6 +2255,52 @@ export interface IOrderModuleService extends IModuleService {
|
|||||||
): Promise<void>
|
): Promise<void>
|
||||||
// Order Change
|
// Order Change
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method retrieves a paginated list of order changes based on optional filters and configuration.
|
||||||
|
*
|
||||||
|
* @param {FilterableOrderChangeProps} filters - The filters to apply on the retrieved order changes.
|
||||||
|
* @param {FindConfig<OrderChangeDTO>} config - The configurations determining how the order exchange is retrieved. Its properties, such as `select` or `relations`, accept the
|
||||||
|
* attributes or relations associated with a order exchange.
|
||||||
|
* @param {Context} sharedContext - A context used to share resources, such as transaction manager, between the application and the module.
|
||||||
|
* @returns {Promise<OrderChangeDTO[]>} The list of order changes.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* To retrieve a list of order changes using their IDs:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* const orderChanges = await orderModuleService.listOrderChanges({
|
||||||
|
* id: ["123", "321"]
|
||||||
|
* })
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* To specify relations that should be retrieved within the exchange:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* const orderChanges = await orderModuleService.listOrderChanges({
|
||||||
|
* id: ["123", "321"]
|
||||||
|
* }, {
|
||||||
|
* relations: ["actions"]
|
||||||
|
* })
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* By default, only the first `15` records are retrieved. You can control pagination by specifying the `skip` and `take` properties of the `config` parameter:
|
||||||
|
*
|
||||||
|
* ```ts
|
||||||
|
* const orderChanges = await orderModuleService.listOrderChanges({
|
||||||
|
* id: ["123", "321"]
|
||||||
|
* }, {
|
||||||
|
* relations: ["actions"],
|
||||||
|
* take: 20,
|
||||||
|
* skip: 2
|
||||||
|
* })
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
listOrderChanges(
|
||||||
|
filters?: FilterableOrderChangeProps,
|
||||||
|
config?: FindConfig<OrderChangeDTO>,
|
||||||
|
sharedContext?: Context
|
||||||
|
): Promise<OrderChangeDTO[]>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method retrieves an order change by its ID.
|
* This method retrieves an order change by its ID.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in new issue
Block a user