Skip to content

Commit 0224558

Browse files
committed
fix(inventory): allow floating-point values for inventory item measurements
Change weight, length, height, width from integer to float on the inventory item model, matching the product module (fixed in #14762). Includes a database migration (int -> real), schema validation update (optionalInt -> optionalFloat), and adds step='any' to all measurement input fields in both create and edit forms so the browser allows decimal input (matching #13863). Closes #16784
1 parent a232298 commit 0224558

7 files changed

Lines changed: 75 additions & 17 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
"@medusajs/inventory": patch
3+
"@medusajs/dashboard": patch
4+
---
5+
6+
fix(inventory): allow floating-point values for inventory item measurements
7+
8+
Changed the inventory item model's weight, length, height, and width
9+
properties from `model.number()` (integer) to `model.float()`, aligning
10+
them with the product and product-variant models that already use float.
11+
12+
Includes a database migration to alter the columns from `int` to `real`,
13+
updates the admin dashboard's create-inventory-item form schema from
14+
`optionalInt` to `optionalFloat`, and adds `step="any"` to all
15+
measurement input fields in both the create and edit forms so the browser
16+
allows decimal input.

packages/admin/dashboard/src/routes/inventory/inventory-create/components/inventory-create-form/inventory-create-form.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ export function InventoryCreateForm({ locations }: InventoryCreateFormProps) {
336336
<Input
337337
{...field}
338338
type="number"
339+
step="any"
339340
min={0}
340341
placeholder="100"
341342
/>
@@ -358,6 +359,7 @@ export function InventoryCreateForm({ locations }: InventoryCreateFormProps) {
358359
<Input
359360
{...field}
360361
type="number"
362+
step="any"
361363
min={0}
362364
placeholder="100"
363365
/>
@@ -380,6 +382,7 @@ export function InventoryCreateForm({ locations }: InventoryCreateFormProps) {
380382
<Input
381383
{...field}
382384
type="number"
385+
step="any"
383386
min={0}
384387
placeholder="100"
385388
/>
@@ -402,6 +405,7 @@ export function InventoryCreateForm({ locations }: InventoryCreateFormProps) {
402405
<Input
403406
{...field}
404407
type="number"
408+
step="any"
405409
min={0}
406410
placeholder="100"
407411
/>

packages/admin/dashboard/src/routes/inventory/inventory-create/components/inventory-create-form/schema.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { z } from "zod"
2-
import { optionalFloat, optionalInt } from "../../../../../lib/validation"
2+
import { optionalFloat } from "../../../../../lib/validation"
33

44
export const CreateInventoryItemSchema = z.object({
55
title: z.string().min(1),
66
description: z.string().optional(),
77
sku: z.string().optional(),
88
hs_code: z.string().optional(),
9-
weight: optionalInt,
10-
length: optionalInt,
11-
height: optionalInt,
12-
width: optionalInt,
9+
weight: optionalFloat,
10+
length: optionalFloat,
11+
height: optionalFloat,
12+
width: optionalFloat,
1313
origin_country: z.string().optional(),
1414
mid_code: z.string().optional(),
1515
material: z.string().optional(),

packages/admin/dashboard/src/routes/inventory/inventory-detail/components/edit-inventory-item-attributes/components/edit-item-attributes-form.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export const EditInventoryItemAttributesForm = ({
9191
<Form.Control>
9292
<Input
9393
type="number"
94+
step="any"
9495
min={0}
9596
value={value || ""}
9697
onChange={(e) => {
@@ -120,6 +121,7 @@ export const EditInventoryItemAttributesForm = ({
120121
<Form.Control>
121122
<Input
122123
type="number"
124+
step="any"
123125
min={0}
124126
value={value || ""}
125127
onChange={(e) => {
@@ -149,6 +151,7 @@ export const EditInventoryItemAttributesForm = ({
149151
<Form.Control>
150152
<Input
151153
type="number"
154+
step="any"
152155
min={0}
153156
value={value || ""}
154157
onChange={(e) => {
@@ -178,6 +181,7 @@ export const EditInventoryItemAttributesForm = ({
178181
<Form.Control>
179182
<Input
180183
type="number"
184+
step="any"
181185
min={0}
182186
value={value || ""}
183187
onChange={(e) => {

packages/modules/inventory/src/migrations/.snapshot-medusa-inventory.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
},
121121
"weight": {
122122
"name": "weight",
123-
"type": "integer",
123+
"type": "real",
124124
"unsigned": false,
125125
"autoincrement": false,
126126
"primary": false,
@@ -132,11 +132,11 @@
132132
"default": null,
133133
"comment": null,
134134
"enumItems": [],
135-
"mappedType": "integer"
135+
"mappedType": "float"
136136
},
137137
"length": {
138138
"name": "length",
139-
"type": "integer",
139+
"type": "real",
140140
"unsigned": false,
141141
"autoincrement": false,
142142
"primary": false,
@@ -148,11 +148,11 @@
148148
"default": null,
149149
"comment": null,
150150
"enumItems": [],
151-
"mappedType": "integer"
151+
"mappedType": "float"
152152
},
153153
"height": {
154154
"name": "height",
155-
"type": "integer",
155+
"type": "real",
156156
"unsigned": false,
157157
"autoincrement": false,
158158
"primary": false,
@@ -164,11 +164,11 @@
164164
"default": null,
165165
"comment": null,
166166
"enumItems": [],
167-
"mappedType": "integer"
167+
"mappedType": "float"
168168
},
169169
"width": {
170170
"name": "width",
171-
"type": "integer",
171+
"type": "real",
172172
"unsigned": false,
173173
"autoincrement": false,
174174
"primary": false,
@@ -180,7 +180,7 @@
180180
"default": null,
181181
"comment": null,
182182
"enumItems": [],
183-
"mappedType": "integer"
183+
"mappedType": "float"
184184
},
185185
"requires_shipping": {
186186
"name": "requires_shipping",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Migration } from "@medusajs/framework/mikro-orm/migrations"
2+
3+
export class Migration20260911000000 extends Migration {
4+
override async up(): Promise<void> {
5+
this.addSql(
6+
`alter table if exists "inventory_item" alter column "weight" type real using ("weight"::real);`
7+
)
8+
this.addSql(
9+
`alter table if exists "inventory_item" alter column "length" type real using ("length"::real);`
10+
)
11+
this.addSql(
12+
`alter table if exists "inventory_item" alter column "height" type real using ("height"::real);`
13+
)
14+
this.addSql(
15+
`alter table if exists "inventory_item" alter column "width" type real using ("width"::real);`
16+
)
17+
}
18+
19+
override async down(): Promise<void> {
20+
this.addSql(
21+
`alter table if exists "inventory_item" alter column "weight" type int using ("weight"::int);`
22+
)
23+
this.addSql(
24+
`alter table if exists "inventory_item" alter column "length" type int using ("length"::int);`
25+
)
26+
this.addSql(
27+
`alter table if exists "inventory_item" alter column "height" type int using ("height"::int);`
28+
)
29+
this.addSql(
30+
`alter table if exists "inventory_item" alter column "width" type int using ("width"::int);`
31+
)
32+
}
33+
}
34+

packages/modules/inventory/src/models/inventory-item.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ const InventoryItem = model
1111
mid_code: model.text().searchable().nullable(),
1212
material: model.text().nullable(),
1313
unit_of_measure: model.text().nullable(),
14-
weight: model.number().nullable(),
15-
length: model.number().nullable(),
16-
height: model.number().nullable(),
17-
width: model.number().nullable(),
14+
weight: model.float().nullable(),
15+
length: model.float().nullable(),
16+
height: model.float().nullable(),
17+
width: model.float().nullable(),
1818
requires_shipping: model.boolean().default(true),
1919
description: model.text().searchable().nullable(),
2020
title: model.text().searchable().nullable(),

0 commit comments

Comments
 (0)