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: update sales order shipment with maximum promised date

Brad Barbin02b8cb80aaae
diff --git a/packages/ee/src/paperless-parts/lib/lib.ts b/packages/ee/src/paperless-parts/lib/lib.ts
index 38fe4055ae..5ef5c8687c 100644
--- a/packages/ee/src/paperless-parts/lib/lib.ts
+++ b/packages/ee/src/paperless-parts/lib/lib.ts
@@ -2268,6 +2268,7 @@ export async function insertOrderLines(
return;
}
+ let maxPromisedDate: string | null = null;
let insertedLinesCount = 0;
const holidays = await carbon
.from("holiday")
@@ -2335,7 +2336,7 @@ export async function insertOrderLines(
defaultTrackingType,
});
- const leadTime = orderItem.lead_days || 7;
+ const leadTime = orderItem.lead_days ?? 7;
const updateLeadTime = await carbon
.from("itemReplenishment")
.update({
@@ -2352,6 +2353,14 @@ export async function insertOrderLines(
holidays.data ?? []
);
+ // Update max promised date if this one is later
+ if (
+ !maxPromisedDate ||
+ (promisedDate && promisedDate > maxPromisedDate)
+ ) {
+ maxPromisedDate = promisedDate;
+ }
+
const saleQuantity =
component.deliver_quantity || orderItem.quantity || 1;
const unitPrice = orderItem.unit_price
@@ -2402,20 +2411,6 @@ export async function insertOrderLines(
continue;
}
- if (promisedDate) {
- const updateShipment = await carbon
- .from("salesOrderShipment")
- .update({
- receiptPromisedDate: promisedDate,
- receiptRequestedDate: promisedDate,
- })
- .eq("id", lineResult.data.id);
-
- if (updateShipment.error) {
- console.error("Failed to update shipment:", updateShipment.error);
- }
- }
-
const lineId = lineResult.data.id;
insertedLinesCount++;
@@ -2469,6 +2464,13 @@ export async function insertOrderLines(
}
}
+ if (maxPromisedDate) {
+ await carbon
+ .from("salesOrderShipment")
+ .update({ receiptPromisedDate: maxPromisedDate })
+ .eq("id", salesOrderId);
+ }
+
if (insertedLinesCount === 0) {
console.warn("No valid order lines were inserted");
return;