From 1be72799f4bbf8938b3c4579b4ac663c01665c7b Mon Sep 17 00:00:00 2001 From: Hagernesh Date: Tue, 11 Aug 2026 12:13:34 +0000 Subject: [PATCH] fix(train-scheduling): exempt direct-to-train export bookings from GRN gate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit confirmScheduleLoading's assertExportBookingsReceived checked every wagon-assigned export booking for a warehouse GRN, with no exception for DIRECT_TO_TRAIN (manual truck-straight-to-wagon) bookings — the one call site that lacked the carve-out already applied everywhere else GRN is checked (export-received-gate, booking-journey, carriage acceptance). Warehouse-routed export cargo still requires GRN; direct handovers rely on the carriage acceptance sheet instead. --- .../train-scheduling/services/train-scheduling.service.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/edr-freight-api/src/modules/train-scheduling/services/train-scheduling.service.ts b/apps/edr-freight-api/src/modules/train-scheduling/services/train-scheduling.service.ts index 657703ada..1cd900d66 100644 --- a/apps/edr-freight-api/src/modules/train-scheduling/services/train-scheduling.service.ts +++ b/apps/edr-freight-api/src/modules/train-scheduling/services/train-scheduling.service.ts @@ -3262,6 +3262,12 @@ export class TrainSchedulingService { * Every export booking being confirmed loaded must already be received at the * warehouse with a GRN. An allocation puts a booking on a wagon on paper; this * is the check that the cargo is physically in the yard before we call it loaded. + * + * Direct truck-to-train (exportHandoverMode = DIRECT_TO_TRAIN) is excluded — + * that cargo is manually loaded from the customer's truck straight onto the + * wagon, never sees the warehouse, and is never GRN'd. Its custody is attested + * by the carriage acceptance sheet instead (same carve-out as the shared + * assertExportReceivedWithGrn gate — see common/export-received-gate.ts). */ private async assertExportBookingsReceived(bookingIds: string[]): Promise { if (!bookingIds.length) return; @@ -3270,6 +3276,7 @@ export class TrainSchedulingService { FROM freight.bookings b WHERE b.id = ANY($1) AND b.deleted_at IS NULL + AND b.export_handover_mode IS DISTINCT FROM 'DIRECT_TO_TRAIN' AND NOT EXISTS ( SELECT 1 FROM freight.warehouse_inventory inv WHERE inv.booking_id = b.id