fix(medusa): Rename quantity to required quantity (#2963)
This commit is contained in:
5
.changeset/seven-sloths-provide.md
Normal file
5
.changeset/seven-sloths-provide.md
Normal file
@@ -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") `
|
||||
)
|
||||
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(
|
||||
`CREATE INDEX "IDX_c74e8c2835094a37dead376a3b" ON "product_variant_inventory_item" ("inventory_item_id") `
|
||||
|
||||
@@ -14,10 +14,44 @@ export class ProductVariantInventoryItem extends BaseEntity {
|
||||
variant_id: string
|
||||
|
||||
@Column({ type: "int", default: 1 })
|
||||
quantity: number
|
||||
required_quantity: number
|
||||
|
||||
@BeforeInsert()
|
||||
private beforeInsert(): void {
|
||||
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(
|
||||
variantInventory.map(async (inventoryPart) => {
|
||||
const itemQuantity = inventoryPart.quantity * quantity
|
||||
const itemQuantity = inventoryPart.required_quantity * quantity
|
||||
return await this.inventoryService_.confirmInventory(
|
||||
inventoryPart.inventory_item_id,
|
||||
locations,
|
||||
@@ -284,7 +284,7 @@ class ProductVariantInventoryService extends TransactionBaseService {
|
||||
const variantInventory = variantInventoryRepo.create({
|
||||
variant_id: variantId,
|
||||
inventory_item_id: inventoryItemId,
|
||||
quantity: quantityToStore,
|
||||
required_quantity: quantityToStore,
|
||||
})
|
||||
|
||||
return await variantInventoryRepo.save(variantInventory)
|
||||
@@ -373,7 +373,7 @@ class ProductVariantInventoryService extends TransactionBaseService {
|
||||
|
||||
await Promise.all(
|
||||
variantInventory.map(async (inventoryPart) => {
|
||||
const itemQuantity = inventoryPart.quantity * quantity
|
||||
const itemQuantity = inventoryPart.required_quantity * quantity
|
||||
return await this.inventoryService_.createReservationItem({
|
||||
...toReserve,
|
||||
location_id: locationId as string,
|
||||
@@ -438,7 +438,8 @@ class ProductVariantInventoryService extends TransactionBaseService {
|
||||
)
|
||||
|
||||
const reservationQtyUpdate =
|
||||
reservation.quantity - quantity * productVariantInventory.quantity
|
||||
reservation.quantity -
|
||||
quantity * productVariantInventory.required_quantity
|
||||
|
||||
if (reservationQtyUpdate === 0) {
|
||||
await this.inventoryService_.deleteReservationItem(reservation.id)
|
||||
@@ -561,7 +562,7 @@ class ProductVariantInventoryService extends TransactionBaseService {
|
||||
|
||||
await Promise.all(
|
||||
variantInventory.map(async (inventoryPart) => {
|
||||
const itemQuantity = inventoryPart.quantity * quantity
|
||||
const itemQuantity = inventoryPart.required_quantity * quantity
|
||||
return await this.inventoryService_.adjustInventory(
|
||||
inventoryPart.inventory_item_id,
|
||||
locationId,
|
||||
|
||||
Reference in New Issue
Block a user