fix(medusa): RMA on items from swaps and claims (#1182)
This commit is contained in:
1 parent
a87e1cdf65
commit
5ae5f15e98
6 files changed
+524
-7
No files matched your search
@@ -1,17 +1,17 @@
|
||||
import { Type } from "class-transformer"
|
||||
import {
|
||||
IsArray,
|
||||
IsOptional,
|
||||
ValidateNested,
|
||||
IsBoolean,
|
||||
IsObject,
|
||||
IsString,
|
||||
IsEnum,
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsEnum,
|
||||
IsObject,
|
||||
IsOptional,
|
||||
IsString,
|
||||
ValidateNested,
|
||||
} from "class-validator"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { defaultAdminOrdersRelations, defaultAdminOrdersFields } from "."
|
||||
import { defaultAdminOrdersFields, defaultAdminOrdersRelations } from "."
|
||||
import { AddressPayload } from "../../../../types/common"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
|
||||
@@ -177,6 +177,12 @@ export default async (req, res) => {
|
||||
"items.tax_lines",
|
||||
"discounts",
|
||||
"discounts.rule",
|
||||
"claims",
|
||||
"claims.additional_items",
|
||||
"claims.additional_items.tax_lines",
|
||||
"swaps",
|
||||
"swaps.additional_items",
|
||||
"swaps.additional_items.tax_lines",
|
||||
],
|
||||
})
|
||||
|
||||
|
||||
@@ -230,7 +230,35 @@ class ClaimService extends BaseService {
|
||||
let toRefund = refund_amount
|
||||
if (type === "refund" && typeof refund_amount === "undefined") {
|
||||
const lines = claim_items.map((ci) => {
|
||||
const orderItem = order.items.find((oi) => oi.id === ci.item_id)
|
||||
const allOrderItems = order.items
|
||||
|
||||
if (order.swaps?.length) {
|
||||
for (const swap of order.swaps) {
|
||||
swap.additional_items.forEach((it) => {
|
||||
if (
|
||||
it.shipped_quantity ||
|
||||
it.shipped_quantity === it.fulfilled_quantity
|
||||
) {
|
||||
allOrderItems.push(it)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (order.claims?.length) {
|
||||
for (const claim of order.claims) {
|
||||
claim.additional_items.forEach((it) => {
|
||||
if (
|
||||
it.shipped_quantity ||
|
||||
it.shipped_quantity === it.fulfilled_quantity
|
||||
) {
|
||||
allOrderItems.push(it)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const orderItem = allOrderItems.find((oi) => oi.id === ci.item_id)
|
||||
return {
|
||||
...orderItem,
|
||||
quantity: ci.quantity,
|
||||
|
||||
@@ -563,6 +563,8 @@ class ReturnService extends BaseService {
|
||||
"region",
|
||||
"swaps",
|
||||
"swaps.additional_items",
|
||||
"claims",
|
||||
"claims.additional_items",
|
||||
],
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user