feat(medusa): Pass location upon receiving returns (#2949)
This commit is contained in:
@@ -39,7 +39,8 @@ describe("POST /admin/returns/:id/receive", () => {
|
||||
IdMap.getId("test-return"),
|
||||
[{ item_id: IdMap.getId("test"), quantity: 2 }],
|
||||
undefined,
|
||||
true
|
||||
true,
|
||||
{ location_id: undefined }
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -5,7 +5,12 @@ import {
|
||||
IsString,
|
||||
ValidateNested,
|
||||
} from "class-validator"
|
||||
import { OrderService, ReturnService, SwapService } from "../../../../services"
|
||||
import {
|
||||
OrderService,
|
||||
ProductVariantInventoryService,
|
||||
ReturnService,
|
||||
SwapService,
|
||||
} from "../../../../services"
|
||||
|
||||
import { EntityManager } from "typeorm"
|
||||
import { Type } from "class-transformer"
|
||||
@@ -98,13 +103,15 @@ export default async (req, res) => {
|
||||
await entityManager.transaction(async (manager) => {
|
||||
let refundAmount = validated.refund
|
||||
|
||||
if (isDefined(validated.refund) && validated.refund < 0) {
|
||||
if (isDefined(validated.refund) && validated.refund! < 0) {
|
||||
refundAmount = 0
|
||||
}
|
||||
|
||||
receivedReturn = await returnService
|
||||
.withTransaction(manager)
|
||||
.receive(id, validated.items, refundAmount, true)
|
||||
.receive(id, validated.items, refundAmount, true, {
|
||||
locationId: validated.location_id,
|
||||
})
|
||||
|
||||
if (receivedReturn.order_id) {
|
||||
await orderService
|
||||
@@ -169,4 +176,8 @@ export class AdminPostReturnsReturnReceiveReq {
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
refund?: number
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
location_id?: string
|
||||
}
|
||||
|
||||
@@ -567,7 +567,8 @@ class ReturnService extends TransactionBaseService {
|
||||
returnId: string,
|
||||
receivedItems: OrdersReturnItem[],
|
||||
refundAmount?: number,
|
||||
allowMismatch = false
|
||||
allowMismatch = false,
|
||||
context: { locationId?: string } = {}
|
||||
): Promise<Return | never> {
|
||||
return await this.atomicPhase_(async (manager) => {
|
||||
const returnRepository = manager.getCustomRepository(
|
||||
@@ -657,6 +658,7 @@ class ReturnService extends TransactionBaseService {
|
||||
const now = new Date()
|
||||
const updateObj = {
|
||||
...returnObj,
|
||||
location_id: context.locationId || returnObj.location_id,
|
||||
status: returnStatus,
|
||||
items: newLines,
|
||||
refund_amount: totalRefundableAmount,
|
||||
@@ -682,7 +684,7 @@ class ReturnService extends TransactionBaseService {
|
||||
if (orderItem && orderItem.variant_id) {
|
||||
await productVarInventoryTx.adjustInventory(
|
||||
orderItem.variant_id,
|
||||
returnObj.location_id!,
|
||||
result.location_id!,
|
||||
line.received_quantity
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user