Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dashboard) admin 3.0 return creation #6713

Merged
merged 24 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d9758fa
feat: initial work
fPolic Mar 14, 2024
fe3f96f
wip: shipping location sections
fPolic Mar 15, 2024
589ee6b
feat: display inventory levels check
fPolic Mar 15, 2024
6ee0699
feat: refundable amount, custom refund and shipping form elements, ad…
fPolic Mar 15, 2024
9990e93
feat: shipping price, translations
fPolic Mar 15, 2024
d1c9863
Merge branch 'develop' into feat/admin-3.0-returns
fPolic Mar 18, 2024
3f91253
fix: status logic, refactor rename
fPolic Mar 18, 2024
dde8ff9
fix: disallow going back to items select
fPolic Mar 18, 2024
7cd6c36
feat: handle return reason
fPolic Mar 18, 2024
d2f6039
fix: fields/defaults and flow
fPolic Mar 18, 2024
caf2135
fix: layout issues, custom shipping price calculations
fPolic Mar 18, 2024
7200fa9
feat: send data
fPolic Mar 18, 2024
01e62f9
feat: open return from details
fPolic Mar 18, 2024
b425241
Merge branch 'develop' into feat/admin-3.0-returns
fPolic Mar 18, 2024
ffb3bd8
Merge branch 'develop' into feat/admin-3.0-returns
fPolic Mar 19, 2024
aef52eb
fix: address comments
fPolic Mar 19, 2024
fa5e3e8
fix: correct tooltip message
fPolic Mar 19, 2024
e900f03
feat: disable shipping select
fPolic Mar 19, 2024
f57ac50
Merge branch 'develop' into feat/admin-3.0-returns
fPolic Mar 20, 2024
b0bb815
Merge branch 'develop' into feat/admin-3.0-returns
fPolic Mar 20, 2024
43c43c7
fix: get returnable items helper
fPolic Mar 21, 2024
0ccf1d2
fix: expands
fPolic Mar 21, 2024
8cd5443
cleanup PR, add table filters, and fix type errors
kasperkristensen Mar 22, 2024
1dc549f
Merge branch 'develop' into feat/admin-3.0-returns
kasperkristensen Mar 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
"is": "is",
"select": "Select",
"selected": "Selected",
"details": "Details",
"enabled": "Enabled",
"disabled": "Disabled",
"expired": "Expired",
"active": "Active",
"revoked": "Revoked",
"admin": "Admin",
"store": "Store",
"details": "Details",
"items_one": "{{count}} item",
"items_other": "{{count}} items",
"countSelected": "{{count}} selected",
Expand All @@ -50,12 +50,13 @@
"settings": "Settings"
},
"actions": {
"save": "Save",
"create": "Create",
"delete": "Delete",
"remove": "Remove",
"revoke": "Revoke",
"cancel": "Cancel",
"save": "Save",
"back": "Back",
"continue": "Continue",
"confirm": "Confirm",
"edit": "Edit",
Expand Down Expand Up @@ -239,6 +240,7 @@
"cancelWarning": "You are about to cancel the order {{id}}. This action cannot be undone.",
"onDateFromSalesChannel": "{{date}} from {{salesChannel}}",
"summary": {
"requestReturn": "Request return",
"allocateItems": "Allocate items",
"editItems": "Edit items"
},
Expand Down Expand Up @@ -270,6 +272,28 @@
"newTotal": "New total",
"differenceDue": "Difference due"
},
"returns": {
"details": "Details",
"chooseItems": "Choose items",
"refundAmount": "Refund amount",
"locationDescription": "Choose which location you want to return the items to.",
"shippingDescription": "Choose which method you want to use for this return.",
"noInventoryLevel": "No inventory level",
"sendNotification": "Send notification",
"sendNotificationHint": "Notify customer of created return.",
"customRefund": "Custom refund",
"shippingPriceTooltip1": "Custom refund is enabled",
"noShippingOptions": "There are no shipping options for the region",
"shippingPriceTooltip2": "Shipping needs to be selected",
"customRefundHint": "If you want to refund something else instead of the total refund.",
"customShippingPrice": "Custom shipping",
"customShippingPriceHint": "Custom shipping cost.",
"noInventoryLevelDesc": "The selected location does not have an inventory level for the selected items. The return can be requested but can’t be received until an inventory level is created for the selected location.",
"refundableAmountLabel": "Refundable amount",
"refundableAmountHeader": "Refundable Amount",
"returnableQuantityLabel": "Returnable quantity",
"returnableQuantityHeader": "Returnable Quantity"
},
"reservations": {
"allocatedLabel": "Allocated",
"notAllocatedLabel": "Not allocated"
Expand Down Expand Up @@ -721,6 +745,8 @@
"limit": "Limit",
"tags": "Tags",
"type": "Type",
"reason": "Reason",
"note": "Note",
"none": "none",
"all": "all",
"percentage": "Percentage",
Expand Down
6 changes: 6 additions & 0 deletions packages/admin-next/dashboard/src/lib/cast-number.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Helper function to cast a z.union([z.number(), z.string()]) to a number
*/
export const castNumber = (number: number | string) => {
return typeof number === "string" ? Number(number.replace(",", ".")) : number
}
75 changes: 75 additions & 0 deletions packages/admin-next/dashboard/src/lib/rma.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { ClaimItem, LineItem, Order } from "@medusajs/medusa"

/**
* Return line items that are returnable from an order
* @param order
* @param isClaim
*/
export const getAllReturnableItems = (
order: Omit<Order, "beforeInserts">,
isClaim: boolean
) => {
let orderItems = order.items.reduce(
(map, obj) =>
map.set(obj.id, {
...obj,
}),
new Map<string, Omit<LineItem, "beforeInsert">>()
)

let claimedItems: ClaimItem[] = []

if (order.claims && order.claims.length) {
for (const claim of order.claims) {
if (claim.return_order?.status !== "canceled") {
claim.claim_items = claim.claim_items ?? []
claimedItems = [...claimedItems, ...claim.claim_items]
}

if (
claim.fulfillment_status === "not_fulfilled" &&
claim.payment_status === "na"
) {
continue
}

if (claim.additional_items && claim.additional_items.length) {
orderItems = claim.additional_items
.filter(
(it) =>
it.shipped_quantity ||
it.shipped_quantity === it.fulfilled_quantity
)
.reduce((map, obj) => map.set(obj.id, { ...obj }), orderItems)
}
}
}

if (!isClaim) {
if (order.swaps && order.swaps.length) {
for (const swap of order.swaps) {
if (swap.fulfillment_status === "not_fulfilled") {
continue
}

orderItems = swap.additional_items.reduce(
(map, obj) =>
map.set(obj.id, {
...obj,
}),
orderItems
)
}
}
}

for (const item of claimedItems) {
const i = orderItems.get(item.item_id)
if (i) {
i.quantity = i.quantity - item.quantity
i.quantity !== 0 ? orderItems.set(i.id, i) : orderItems.delete(i.id)
}
}

return [...orderItems.values()]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type {
AdminCollectionsRes,
AdminCustomerGroupsRes,
AdminCustomersRes,
AdminDraftOrdersRes,
AdminDiscountsRes,
AdminDraftOrdersRes,
AdminGiftCardsRes,
AdminOrdersRes,
AdminProductsRes,
Expand Down Expand Up @@ -124,6 +124,11 @@ export const v1Routes: RouteObject[] = [
path: "edit",
lazy: () => import("../../routes/orders/order-edit"),
},
{
path: "returns",
lazy: () =>
import("../../routes/orders/order-create-return"),
},
],
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { z } from "zod"

export const CreateReturnSchema = z.object({
quantity: z.record(z.string(), z.number()),
reason: z.record(z.string(), z.string().optional()),
note: z.record(z.string(), z.string().optional()),
location: z.string(),
shipping: z.string(),
send_notification: z.boolean().optional(),

enable_custom_refund: z.boolean().optional(),
enable_custom_shipping_price: z.boolean().optional(),

custom_refund: z.union([z.string(), z.number()]).optional(),
custom_shipping_price: z.union([z.string(), z.number()]).optional(),
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { OrderCreateReturnForm as CreateReturns } from "./order-create-return-form"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./order-create-return-details"
Loading
Loading