Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/fix-inventory-item-float-measurements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@medusajs/inventory": patch
"@medusajs/dashboard": patch
---

fix(inventory): allow floating-point values for inventory item measurements

Changed the inventory item model's weight, length, height, and width
properties from `model.number()` (integer) to `model.float()`, aligning
them with the product and product-variant models that already use float.

Includes a database migration to alter the columns from `int` to `real`,
updates the admin dashboard's create-inventory-item form schema from
`optionalInt` to `optionalFloat`, and adds `step="any"` to all
measurement input fields in both the create and edit forms so the browser
allows decimal input.
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export function InventoryCreateForm({ locations }: InventoryCreateFormProps) {
<Input
{...field}
type="number"
step="any"
min={0}
placeholder="100"
/>
Expand All @@ -358,6 +359,7 @@ export function InventoryCreateForm({ locations }: InventoryCreateFormProps) {
<Input
{...field}
type="number"
step="any"
min={0}
placeholder="100"
/>
Expand All @@ -380,6 +382,7 @@ export function InventoryCreateForm({ locations }: InventoryCreateFormProps) {
<Input
{...field}
type="number"
step="any"
min={0}
placeholder="100"
/>
Expand All @@ -402,6 +405,7 @@ export function InventoryCreateForm({ locations }: InventoryCreateFormProps) {
<Input
{...field}
type="number"
step="any"
min={0}
placeholder="100"
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { z } from "zod"
import { optionalFloat, optionalInt } from "../../../../../lib/validation"
import { optionalFloat } from "../../../../../lib/validation"

export const CreateInventoryItemSchema = z.object({
title: z.string().min(1),
description: z.string().optional(),
sku: z.string().optional(),
hs_code: z.string().optional(),
weight: optionalInt,
length: optionalInt,
height: optionalInt,
width: optionalInt,
weight: optionalFloat,
length: optionalFloat,
height: optionalFloat,
width: optionalFloat,
origin_country: z.string().optional(),
mid_code: z.string().optional(),
material: z.string().optional(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const EditInventoryItemAttributesForm = ({
<Form.Control>
<Input
type="number"
step="any"
min={0}
value={value || ""}
onChange={(e) => {
Expand Down Expand Up @@ -120,6 +121,7 @@ export const EditInventoryItemAttributesForm = ({
<Form.Control>
<Input
type="number"
step="any"
min={0}
value={value || ""}
onChange={(e) => {
Expand Down Expand Up @@ -149,6 +151,7 @@ export const EditInventoryItemAttributesForm = ({
<Form.Control>
<Input
type="number"
step="any"
min={0}
value={value || ""}
onChange={(e) => {
Expand Down Expand Up @@ -178,6 +181,7 @@ export const EditInventoryItemAttributesForm = ({
<Form.Control>
<Input
type="number"
step="any"
min={0}
value={value || ""}
onChange={(e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
},
"weight": {
"name": "weight",
"type": "integer",
"type": "real",
"unsigned": false,
"autoincrement": false,
"primary": false,
Expand All @@ -132,11 +132,11 @@
"default": null,
"comment": null,
"enumItems": [],
"mappedType": "integer"
"mappedType": "float"
},
"length": {
"name": "length",
"type": "integer",
"type": "real",
"unsigned": false,
"autoincrement": false,
"primary": false,
Expand All @@ -148,11 +148,11 @@
"default": null,
"comment": null,
"enumItems": [],
"mappedType": "integer"
"mappedType": "float"
},
"height": {
"name": "height",
"type": "integer",
"type": "real",
"unsigned": false,
"autoincrement": false,
"primary": false,
Expand All @@ -164,11 +164,11 @@
"default": null,
"comment": null,
"enumItems": [],
"mappedType": "integer"
"mappedType": "float"
},
"width": {
"name": "width",
"type": "integer",
"type": "real",
"unsigned": false,
"autoincrement": false,
"primary": false,
Expand All @@ -180,7 +180,7 @@
"default": null,
"comment": null,
"enumItems": [],
"mappedType": "integer"
"mappedType": "float"
},
"requires_shipping": {
"name": "requires_shipping",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Migration } from "@medusajs/framework/mikro-orm/migrations"

export class Migration20260911000000 extends Migration {
override async up(): Promise<void> {
this.addSql(
`alter table if exists "inventory_item" alter column "weight" type real using ("weight"::real);`
)
this.addSql(
`alter table if exists "inventory_item" alter column "length" type real using ("length"::real);`
)
this.addSql(
`alter table if exists "inventory_item" alter column "height" type real using ("height"::real);`
)
this.addSql(
`alter table if exists "inventory_item" alter column "width" type real using ("width"::real);`
)
}

override async down(): Promise<void> {
this.addSql(
`alter table if exists "inventory_item" alter column "weight" type int using ("weight"::int);`
)
this.addSql(
`alter table if exists "inventory_item" alter column "length" type int using ("length"::int);`
)
this.addSql(
`alter table if exists "inventory_item" alter column "height" type int using ("height"::int);`
)
this.addSql(
`alter table if exists "inventory_item" alter column "width" type int using ("width"::int);`
)
}
}

8 changes: 4 additions & 4 deletions packages/modules/inventory/src/models/inventory-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ const InventoryItem = model
mid_code: model.text().searchable().nullable(),
material: model.text().nullable(),
unit_of_measure: model.text().nullable(),
weight: model.number().nullable(),
length: model.number().nullable(),
height: model.number().nullable(),
width: model.number().nullable(),
weight: model.float().nullable(),
length: model.float().nullable(),
height: model.float().nullable(),
width: model.float().nullable(),
requires_shipping: model.boolean().default(true),
description: model.text().searchable().nullable(),
title: model.text().searchable().nullable(),
Expand Down
Loading