Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: add checks for undefined shipped quantities on shipment lines

Brad Barbine705e4048a32
diff --git a/apps/erp/app/modules/inventory/ui/Shipments/ShipmentLines.tsx b/apps/erp/app/modules/inventory/ui/Shipments/ShipmentLines.tsx
index c99fd1f694..632f4add5a 100644
--- a/apps/erp/app/modules/inventory/ui/Shipments/ShipmentLines.tsx
+++ b/apps/erp/app/modules/inventory/ui/Shipments/ShipmentLines.tsx
@@ -91,7 +91,10 @@ const ShipmentLines = () => {
shipmentsById.set(pendingShipmentLine.id, merged as ShipmentLine);
}
- const shipmentLines = Array.from(shipmentsById.values());
+ const shipmentLines = Array.from(shipmentsById.values().map((line) => ({
+ ...line,
+ shippedQuantity: line.shippedQuantity ?? 0,
+ })));
const [serialNumbersByLineId, setSerialNumbersByLineId] = useState<
Record<string, { index: number; id: string }[]>
diff --git a/packages/database/supabase/functions/create-inventory-document/index.ts b/packages/database/supabase/functions/create-inventory-document/index.ts
index ff40b25a0c..93989bd595 100644
--- a/packages/database/supabase/functions/create-inventory-document/index.ts
+++ b/packages/database/supabase/functions/create-inventory-document/index.ts
@@ -753,7 +753,7 @@ serve(async (req: Request) => {
itemReadableId: salesOrderLine.itemReadableId,
orderQuantity: salesOrderLine.saleQuantity,
outstandingQuantity: outstandingQuantity,
- shippedQuantity: outstandingQuantity,
+ shippedQuantity: outstandingQuantity ?? 0,
requiresSerialTracking: isSerial,
requiresBatchTracking: isBatch,
unitPrice: shippingAndTaxUnitCost,
diff --git a/packages/database/supabase/functions/post-shipment/index.ts b/packages/database/supabase/functions/post-shipment/index.ts
index 4a1ce0fc1e..c86cc77acb 100644
--- a/packages/database/supabase/functions/post-shipment/index.ts
+++ b/packages/database/supabase/functions/post-shipment/index.ts
@@ -241,12 +241,15 @@ serve(async (req: Request) => {
items.data.find((item) => item.id === shipmentLine.itemId)
?.itemTrackingType ?? "Inventory";
+ // Default shippedQuantity to 0 if not defined
+ const shippedQuantity = shipmentLine.shippedQuantity ?? 0;
+
if (itemTrackingType === "Inventory") {
itemLedgerInserts.push({
postingDate: today,
itemId: shipmentLine.itemId,
itemReadableId: shipmentLine.itemReadableId ?? "",
- quantity: -shipmentLine.shippedQuantity,
+ quantity: -shippedQuantity,
locationId: shipmentLine.locationId ?? locationId,
shelfId: shipmentLine.shelfId,
entryType: "Negative Adjmt.",
@@ -263,7 +266,7 @@ serve(async (req: Request) => {
postingDate: today,
itemId: shipmentLine.itemId,
itemReadableId: shipmentLine.itemReadableId ?? "",
- quantity: -shipmentLine.shippedQuantity,
+ quantity: -shippedQuantity,
locationId: shipmentLine.locationId ?? locationId,
shelfId: shipmentLine.shelfId,
entryType: "Negative Adjmt.",