fix(core-flows,order): return damaged items (#8818)

This commit is contained in:
Carlos R. L. Rodrigues
2024-08-27 11:21:10 -03:00
committed by GitHub
parent 0c4f4c8a11
commit ff6fcfb139
5 changed files with 56 additions and 0 deletions

View File

@@ -973,6 +973,7 @@ medusaIntegrationTestRunner({
items: [
expect.objectContaining({
received_quantity: 2,
damaged_quantity: 1,
}),
],
})

View File

@@ -237,12 +237,24 @@ export const confirmReturnReceiveWorkflow = createWorkflow(
itemUpdates[itemId].received_quantity,
act.details!.quantity as BigNumberInput
)
if (act.action === ChangeActionType.RECEIVE_DAMAGED_RETURN_ITEM) {
itemUpdates[itemId].damaged_quantity = MathBN.add(
itemUpdates[itemId].damaged_quantity,
act.details!.quantity as BigNumberInput
)
}
return
}
itemUpdates[itemId] = {
id: itemMap[itemId],
received_quantity: act.details!.quantity,
damaged_quantity:
act.action === ChangeActionType.RECEIVE_DAMAGED_RETURN_ITEM
? act.details!.quantity
: 0,
}
})

View File

@@ -3685,6 +3685,25 @@
"nullable": false,
"mappedType": "json"
},
"damaged_quantity": {
"name": "damaged_quantity",
"type": "numeric",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"default": "0",
"mappedType": "decimal"
},
"raw_damaged_quantity": {
"name": "raw_damaged_quantity",
"type": "jsonb",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"mappedType": "json"
},
"return_id": {
"name": "return_id",
"type": "text",

View File

@@ -0,0 +1,18 @@
import { Migration } from "@mikro-orm/migrations"
export class Migration20240827133639 extends Migration {
async up(): Promise<void> {
this.addSql(
'alter table if exists "return_item" add column if not exists "damaged_quantity" numeric not null default 0, add column if not exists "raw_damaged_quantity" jsonb not null;'
)
}
async down(): Promise<void> {
this.addSql(
'alter table if exists "return_item" drop column if exists "damaged_quantity";'
)
this.addSql(
'alter table if exists "return_item" drop column if exists "raw_damaged_quantity";'
)
}
}

View File

@@ -77,6 +77,12 @@ export default class ReturnItem {
@Property({ columnType: "jsonb" })
raw_received_quantity: BigNumberRawValue
@MikroOrmBigNumberProperty()
damaged_quantity: Number | number = 0
@Property({ columnType: "jsonb" })
raw_damaged_quantity: BigNumberRawValue
@ManyToOne(() => Return, {
columnType: "text",
fieldName: "return_id",