fix(inventory): allow floating-point values for inventory item measurements - #16785
fix(inventory): allow floating-point values for inventory item measurements#16785coderlucifer wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 0224558 The changes in this PR will be included in the next version bump. This PR includes changesets to release 83 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for the contribution! Initial automated review looks good. The contributor adds support for floating-point values in the inventory item measurement fields (weight, length, height, width), aligning them with the product/variant models that were updated to use model.float() in an earlier change. All relevant layers are consistently updated: the data model switches from model.number() to model.float(), the database migration correctly uses ALTER COLUMN ... TYPE real USING ("column"::real) with a reversible down(), the MikroORM snapshot reflects the new type: real / mappedType: float, and the admin dashboard create-form schema switches from optionalInt to optionalFloat. The optionalFloat validator already exists in the validation library and enforces a non-negative constraint while accepting decimal input. The changeset is correctly included and formatted. No tests are added, but for a trivial column-type alignment bug fix this is within the range of accepted minor-fix omissions per project conventions. No security, performance, or correctness issues were found. Triggered by: new PR opened |
|
@coderlucifer I suspect you didn't test this change manually. Because the UI needs updating too. See #13863 for inspiration. |
…ements Change weight, length, height, width from integer to float on the inventory item model, matching the product module (fixed in medusajs#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 medusajs#13863). Closes medusajs#16784
7e52850 to
0224558
Compare
Thanks for the catch @e1himself! You're right — I missed the UI layer. I've now pushed an update that adds
This matches what was done in #13863 for the product attributes. Without The full fix now covers all three layers:
|
What
Allow inventory item measurement fields (weight, length, height, width) to store floating-point values like
0.1or4.5.Fixes #16784
Why
PR #14762 aligned product and product-variant volumetric attributes to use
model.float()(mapped torealin Postgres), but the inventory item model was not updated in that PR. It still usesmodel.number()which maps to anintegercolumn, so values like0.5 kgor12.3 cmget truncated to whole numbers — both in the database and the admin dashboard create form (which usedoptionalIntvalidation).How
Same approach as #14762, applied to the inventory item module:
Data model (
packages/modules/inventory/src/models/inventory-item.ts):Changed
model.number()tomodel.float()for weight, length, height, and width.Database migration (
packages/modules/inventory/src/migrations/Migration20260911000000.ts):ALTER COLUMN ... TYPE real USING ("column"::real)converts the four columns frominttoreal. Includes a reversibledown()that reverts toint. Uses explicitUSINGcast as flagged in the fix(product, dashboard): align product and variant volumetric attributes data types #14762 review.Admin dashboard (
packages/admin/dashboard/src/.../inventory-create-form/schema.ts):Changed form validation from
optionalInttooptionalFloatso the create inventory item form accepts decimal input. The edit form already usesz.number().positive().optional()which accepts floats.Migration snapshot (
.snapshot-medusa-inventory.json):Updated
typefrom"integer"to"real"andmappedTypefrom"integer"to"float"for all four fields.No changes needed to API validators (
z.number()already accepts floats) or TypeScript types (numberalready accepts floats).Testing
turbo run build --filter=@medusajs/inventory...— 13/13 packages)model.float()pattern from fix(product, dashboard): align product and variant volumetric attributes data types #14762