Auto-fill AssetItem.warrantyEndDate from AssetModel.warrantyMonths
CI / test (push) Failing after 8s

AssetModel gains an optional warrantyMonths (standard vendor warranty
length). createAssetItem() now defaults warrantyEndDate to purchaseDate +
warrantyMonths (month-end clamped, e.g. Dec 31 + 2mo -> Feb 28, not Mar 3)
whenever the caller omits warrantyEndDate -- still overridable per item
for batches with extended/different warranty terms. /asset-models UI gets
an input for the new field; /assets needs no change since it already
omits warrantyEndDate from the payload when left blank.

Hand-written migration + manual smoke test (tsx script, not Vitest),
same deviation as the other 2026-08-2x work in this branch -- see
CLAUDE.md. tsc/lint clean.
This commit is contained in:
toanhoang
2026-08-21 09:10:55 -04:00
parent 8ac95c974b
commit d9b360c1df
7 changed files with 110 additions and 4 deletions
+10
View File
@@ -364,6 +364,16 @@ model AssetModel {
manufacturer String
name String
specs Json @default("{}")
// Standard manufacturer/vendor warranty length for this model, in months
// (e.g. Dell Latitude 5420 -> 36). Nullable -- not every model has a known
// standard term. Used only as a DEFAULT when creating an AssetItem: see
// src/lib/assets.ts's createAssetItem() -- warrantyEndDate = purchaseDate
// + warrantyMonths, computed server-side only when the caller doesn't
// supply warrantyEndDate explicitly (2026-08-21 decision: a specific
// purchase batch's actual warranty can differ from the model's standard
// term -- e.g. an extended-warranty deal -- so this must stay an
// overridable suggestion, not a hard-locked computed column on AssetItem).
warrantyMonths Int? @map("warranty_months")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
// Back-relation for the AssetItem.model -> AssetItem.modelId retrofit —
// see "Cập nhật 2026-08-02 (2)" in docs/asset-license-management.md.