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.

fix: handle partial shipments and receipt tracking

Brad Barbin43daacd35238
diff --git a/apps/erp/app/routes/x+/receipt+/$receiptId.details.tsx b/apps/erp/app/routes/x+/receipt+/$receiptId.details.tsx
index 488689c4ad..41b8360bbc 100644
--- a/apps/erp/app/routes/x+/receipt+/$receiptId.details.tsx
+++ b/apps/erp/app/routes/x+/receipt+/$receiptId.details.tsx
@@ -138,7 +138,7 @@ export default function ReceiptDetailsRoute() {
};
return (
- <>
+ <div className="flex flex-col gap-2 pb-16 w-full">
<ReceiptForm
key={initialValues.sourceDocumentId}
// @ts-ignore
@@ -156,6 +156,6 @@ export default function ReceiptDetailsRoute() {
table="receipt"
internalNotes={routeData.receipt.internalNotes as JSONContent}
/>
- </>
+ </div>
);
}
diff --git a/packages/database/supabase/functions/post-receipt/index.ts b/packages/database/supabase/functions/post-receipt/index.ts
index 64b9f13947..a64e4a5029 100644
--- a/packages/database/supabase/functions/post-receipt/index.ts
+++ b/packages/database/supabase/functions/post-receipt/index.ts
@@ -154,6 +154,27 @@ serve(async (req: Request) => {
return acc;
}, {});
+ const itemTrackingUpdates =
+ receiptLineTracking.data?.reduce<
+ Record<
+ string,
+ Database["public"]["Tables"]["itemTracking"]["Update"]
+ >
+ >((acc, itemTracking) => {
+ const quantity =
+ receiptLines.data?.find(
+ (receiptLine) =>
+ receiptLine.id === itemTracking.sourceDocumentLineId
+ )?.receivedQuantity ?? itemTracking.quantity;
+
+ acc[itemTracking.id] = {
+ posted: true,
+ quantity: quantity,
+ };
+
+ return acc;
+ }, {}) ?? {};
+
const purchaseOrderLineUpdates = purchaseOrderLines.data.reduce<
Record<
string,
@@ -810,13 +831,17 @@ serve(async (req: Request) => {
.where("id", "=", receiptId)
.execute();
- await trx
- .updateTable("itemTracking")
- .set({
- posted: true,
- })
- .where("sourceDocumentId", "=", receiptId)
- .execute();
+ if (Object.keys(itemTrackingUpdates).length > 0) {
+ for await (const [id, update] of Object.entries(
+ itemTrackingUpdates
+ )) {
+ await trx
+ .updateTable("itemTracking")
+ .set(update)
+ .where("id", "=", id)
+ .execute();
+ }
+ }
});
break;
}
diff --git a/packages/database/supabase/functions/post-shipment/index.ts b/packages/database/supabase/functions/post-shipment/index.ts
index 6ba46a25ea..2fad68a752 100644
--- a/packages/database/supabase/functions/post-shipment/index.ts
+++ b/packages/database/supabase/functions/post-shipment/index.ts
@@ -242,7 +242,7 @@ serve(async (req: Request) => {
const sentComplete =
salesOrderLine.sentComplete ||
- shippedQuantity >= salesOrderLine.saleQuantity;
+ newQuantitySent >= salesOrderLine.saleQuantity;
const updates: Record<
string,
@@ -265,6 +265,27 @@ serve(async (req: Request) => {
return acc;
}, {});
+ const itemTrackingUpdates =
+ shipmentLineTracking.data?.reduce<
+ Record<
+ string,
+ Database["public"]["Tables"]["itemTracking"]["Update"]
+ >
+ >((acc, itemTracking) => {
+ const quantity =
+ shipmentLines.data?.find(
+ (shipmentLine) =>
+ shipmentLine.id === itemTracking.sourceDocumentLineId
+ )?.shippedQuantity ?? itemTracking.quantity;
+
+ acc[itemTracking.id] = {
+ posted: true,
+ quantity: quantity,
+ };
+
+ return acc;
+ }, {}) ?? {};
+
await db.transaction().execute(async (trx) => {
for await (const [salesOrderLineId, update] of Object.entries(
salesOrderLineUpdates
@@ -332,13 +353,17 @@ serve(async (req: Request) => {
.where("id", "=", shipmentId)
.execute();
- await trx
- .updateTable("itemTracking")
- .set({
- posted: true,
- })
- .where("sourceDocumentId", "=", shipmentId)
- .execute();
+ if (Object.keys(itemTrackingUpdates).length > 0) {
+ for await (const [id, update] of Object.entries(
+ itemTrackingUpdates
+ )) {
+ await trx
+ .updateTable("itemTracking")
+ .set(update)
+ .where("id", "=", id)
+ .execute();
+ }
+ }
if (serialNumbersConsumed.length > 0) {
await trx