chore(inventory, core-flows): big number support (#8204)
This commit is contained in:
committed by
GitHub
parent
c307972a99
commit
fb29b958fa
@@ -32,6 +32,7 @@ const InventoryItemSkuIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "inventory_item",
|
||||
columns: "sku",
|
||||
unique: true,
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
type InventoryItemOptionalProps = DAL.SoftDeletableModelDateColumns
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DALUtils, isDefined } from "@medusajs/utils"
|
||||
import { DALUtils, isDefined, MathBN } from "@medusajs/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
@@ -11,9 +11,12 @@ import {
|
||||
Rel,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
import { BigNumberRawValue } from "@medusajs/types"
|
||||
import {
|
||||
BigNumber,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
MikroOrmBigNumberProperty,
|
||||
} from "@medusajs/utils"
|
||||
import { InventoryItem } from "./inventory-item"
|
||||
|
||||
@@ -26,17 +29,21 @@ const InventoryLevelDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
const InventoryLevelInventoryItemIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "inventory_level",
|
||||
columns: "inventory_item_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const InventoryLevelLocationIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "inventory_level",
|
||||
columns: "location_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const InventoryLevelLocationIdInventoryItemIdIndex =
|
||||
createPsqlIndexStatementHelper({
|
||||
tableName: "inventory_level",
|
||||
columns: "location_id",
|
||||
columns: ["inventory_item_id", "location_id"],
|
||||
unique: true,
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@@ -78,14 +85,23 @@ export class InventoryLevel {
|
||||
@Property({ type: "text" })
|
||||
location_id: string
|
||||
|
||||
@Property({ type: "int" })
|
||||
stocked_quantity: number = 0
|
||||
@MikroOrmBigNumberProperty()
|
||||
stocked_quantity: BigNumber | number = 0
|
||||
|
||||
@Property({ type: "int" })
|
||||
reserved_quantity: number = 0
|
||||
@Property({ columnType: "jsonb" })
|
||||
raw_stocked_quantity: BigNumberRawValue
|
||||
|
||||
@Property({ type: "int" })
|
||||
incoming_quantity: number = 0
|
||||
@MikroOrmBigNumberProperty()
|
||||
reserved_quantity: BigNumber | number = 0
|
||||
|
||||
@Property({ columnType: "jsonb" })
|
||||
raw_reserved_quantity: BigNumberRawValue
|
||||
|
||||
@MikroOrmBigNumberProperty()
|
||||
incoming_quantity: BigNumber | number = 0
|
||||
|
||||
@Property({ columnType: "jsonb" })
|
||||
raw_incoming_quantity: BigNumberRawValue
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null
|
||||
@@ -95,7 +111,7 @@ export class InventoryLevel {
|
||||
})
|
||||
inventory_item: Rel<InventoryItem>
|
||||
|
||||
available_quantity: number | null = null
|
||||
available_quantity: BigNumber | number | null = null
|
||||
|
||||
@BeforeCreate()
|
||||
private beforeCreate(): void {
|
||||
@@ -111,7 +127,9 @@ export class InventoryLevel {
|
||||
@OnLoad()
|
||||
private onLoad(): void {
|
||||
if (isDefined(this.stocked_quantity) && isDefined(this.reserved_quantity)) {
|
||||
this.available_quantity = this.stocked_quantity - this.reserved_quantity
|
||||
this.available_quantity = new BigNumber(
|
||||
MathBN.sub(this.raw_stocked_quantity, this.raw_reserved_quantity)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,11 @@ import {
|
||||
Rel,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
import { BigNumberRawValue } from "@medusajs/types"
|
||||
import {
|
||||
BigNumber,
|
||||
DALUtils,
|
||||
MikroOrmBigNumberProperty,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/utils"
|
||||
@@ -24,16 +27,19 @@ const ReservationItemDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
const ReservationItemLineItemIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "reservation_item",
|
||||
columns: "line_item_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const ReservationItemInventoryItemIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "reservation_item",
|
||||
columns: "inventory_item_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
const ReservationItemLocationIdIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "reservation_item",
|
||||
columns: "location_id",
|
||||
where: "deleted_at IS NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@@ -72,8 +78,11 @@ export class ReservationItem {
|
||||
@Property({ type: "text" })
|
||||
location_id: string
|
||||
|
||||
@Property({ columnType: "integer" })
|
||||
quantity: number
|
||||
@MikroOrmBigNumberProperty()
|
||||
quantity: BigNumber | number
|
||||
|
||||
@Property({ columnType: "jsonb" })
|
||||
raw_quantity: BigNumberRawValue
|
||||
|
||||
@Property({ type: "text", nullable: true })
|
||||
external_id: string | null = null
|
||||
|
||||
Reference in New Issue
Block a user