fix(medusa): Rename quantity to required quantity (#2963)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix(medusa): rename variant inventory item quantity to required_quantity
|
||||||
@@ -14,7 +14,7 @@ export class multiLocation1671711415179 implements MigrationInterface {
|
|||||||
`CREATE INDEX "IDX_c2203162ca946a71aeb98390b0" ON "sales_channel_location" ("location_id") `
|
`CREATE INDEX "IDX_c2203162ca946a71aeb98390b0" ON "sales_channel_location" ("location_id") `
|
||||||
)
|
)
|
||||||
await queryRunner.query(
|
await queryRunner.query(
|
||||||
`CREATE TABLE "product_variant_inventory_item" ("id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "inventory_item_id" text NOT NULL, "variant_id" text NOT NULL, "quantity" integer NOT NULL DEFAULT '1', CONSTRAINT "UQ_c9be7c1b11a1a729eb51d1b6bca" UNIQUE ("variant_id", "inventory_item_id"), CONSTRAINT "PK_9a1188b8d36f4d198303b4f7efa" PRIMARY KEY ("id"))`
|
`CREATE TABLE "product_variant_inventory_item" ("id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "inventory_item_id" text NOT NULL, "variant_id" text NOT NULL, "required_quantity" integer NOT NULL DEFAULT '1', CONSTRAINT "UQ_c9be7c1b11a1a729eb51d1b6bca" UNIQUE ("variant_id", "inventory_item_id"), CONSTRAINT "PK_9a1188b8d36f4d198303b4f7efa" PRIMARY KEY ("id"))`
|
||||||
)
|
)
|
||||||
await queryRunner.query(
|
await queryRunner.query(
|
||||||
`CREATE INDEX "IDX_c74e8c2835094a37dead376a3b" ON "product_variant_inventory_item" ("inventory_item_id") `
|
`CREATE INDEX "IDX_c74e8c2835094a37dead376a3b" ON "product_variant_inventory_item" ("inventory_item_id") `
|
||||||
|
|||||||
@@ -14,10 +14,44 @@ export class ProductVariantInventoryItem extends BaseEntity {
|
|||||||
variant_id: string
|
variant_id: string
|
||||||
|
|
||||||
@Column({ type: "int", default: 1 })
|
@Column({ type: "int", default: 1 })
|
||||||
quantity: number
|
required_quantity: number
|
||||||
|
|
||||||
@BeforeInsert()
|
@BeforeInsert()
|
||||||
private beforeInsert(): void {
|
private beforeInsert(): void {
|
||||||
this.id = generateEntityId(this.id, "pvitem")
|
this.id = generateEntityId(this.id, "pvitem")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @schema ProductVariantInventoryItem
|
||||||
|
* title: "Product Variant Inventory Item"
|
||||||
|
* description: "Product Variant Inventory Items link variants with inventory items and denote the number of inventory items constituting a variant."
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* id:
|
||||||
|
* type: string
|
||||||
|
* description: The product variant inventory item's ID
|
||||||
|
* example: pvitem_01G8X9A7ESKAJXG2H0E6F1MW7A
|
||||||
|
* inventory_item_id:
|
||||||
|
* description: "The id of the inventory item"
|
||||||
|
* type: string
|
||||||
|
* variant_id:
|
||||||
|
* description: "The id of the variant."
|
||||||
|
* type: string
|
||||||
|
* required_quantity:
|
||||||
|
* description: "The quantity of an inventory item required for one quantity of the variant."
|
||||||
|
* type: integer
|
||||||
|
* default: 1
|
||||||
|
* created_at:
|
||||||
|
* type: string
|
||||||
|
* description: "The date with timezone at which the resource was created."
|
||||||
|
* format: date-time
|
||||||
|
* updated_at:
|
||||||
|
* type: string
|
||||||
|
* description: "The date with timezone at which the resource was updated."
|
||||||
|
* format: date-time
|
||||||
|
* deleted_at:
|
||||||
|
* type: string
|
||||||
|
* description: "The date with timezone at which the resource was deleted."
|
||||||
|
* format: date-time
|
||||||
|
*/
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ class ProductVariantInventoryService extends TransactionBaseService {
|
|||||||
|
|
||||||
const hasInventory = await Promise.all(
|
const hasInventory = await Promise.all(
|
||||||
variantInventory.map(async (inventoryPart) => {
|
variantInventory.map(async (inventoryPart) => {
|
||||||
const itemQuantity = inventoryPart.quantity * quantity
|
const itemQuantity = inventoryPart.required_quantity * quantity
|
||||||
return await this.inventoryService_.confirmInventory(
|
return await this.inventoryService_.confirmInventory(
|
||||||
inventoryPart.inventory_item_id,
|
inventoryPart.inventory_item_id,
|
||||||
locations,
|
locations,
|
||||||
@@ -284,7 +284,7 @@ class ProductVariantInventoryService extends TransactionBaseService {
|
|||||||
const variantInventory = variantInventoryRepo.create({
|
const variantInventory = variantInventoryRepo.create({
|
||||||
variant_id: variantId,
|
variant_id: variantId,
|
||||||
inventory_item_id: inventoryItemId,
|
inventory_item_id: inventoryItemId,
|
||||||
quantity: quantityToStore,
|
required_quantity: quantityToStore,
|
||||||
})
|
})
|
||||||
|
|
||||||
return await variantInventoryRepo.save(variantInventory)
|
return await variantInventoryRepo.save(variantInventory)
|
||||||
@@ -373,7 +373,7 @@ class ProductVariantInventoryService extends TransactionBaseService {
|
|||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
variantInventory.map(async (inventoryPart) => {
|
variantInventory.map(async (inventoryPart) => {
|
||||||
const itemQuantity = inventoryPart.quantity * quantity
|
const itemQuantity = inventoryPart.required_quantity * quantity
|
||||||
return await this.inventoryService_.createReservationItem({
|
return await this.inventoryService_.createReservationItem({
|
||||||
...toReserve,
|
...toReserve,
|
||||||
location_id: locationId as string,
|
location_id: locationId as string,
|
||||||
@@ -438,7 +438,8 @@ class ProductVariantInventoryService extends TransactionBaseService {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const reservationQtyUpdate =
|
const reservationQtyUpdate =
|
||||||
reservation.quantity - quantity * productVariantInventory.quantity
|
reservation.quantity -
|
||||||
|
quantity * productVariantInventory.required_quantity
|
||||||
|
|
||||||
if (reservationQtyUpdate === 0) {
|
if (reservationQtyUpdate === 0) {
|
||||||
await this.inventoryService_.deleteReservationItem(reservation.id)
|
await this.inventoryService_.deleteReservationItem(reservation.id)
|
||||||
@@ -561,7 +562,7 @@ class ProductVariantInventoryService extends TransactionBaseService {
|
|||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
variantInventory.map(async (inventoryPart) => {
|
variantInventory.map(async (inventoryPart) => {
|
||||||
const itemQuantity = inventoryPart.quantity * quantity
|
const itemQuantity = inventoryPart.required_quantity * quantity
|
||||||
return await this.inventoryService_.adjustInventory(
|
return await this.inventoryService_.adjustInventory(
|
||||||
inventoryPart.inventory_item_id,
|
inventoryPart.inventory_item_id,
|
||||||
locationId,
|
locationId,
|
||||||
|
|||||||
Reference in New Issue
Block a user