diff --git a/apps/edr-freight-api/src/modules/train-scheduling/booking-journey.service.ts b/apps/edr-freight-api/src/modules/train-scheduling/booking-journey.service.ts index 50835d5b0..87e756ba6 100644 --- a/apps/edr-freight-api/src/modules/train-scheduling/booking-journey.service.ts +++ b/apps/edr-freight-api/src/modules/train-scheduling/booking-journey.service.ts @@ -327,11 +327,19 @@ export class BookingJourneyService { RETURNING b.id, b.trade_direction`, [schedule.id, schedule.destinationStationId, now], ); - // Intercity rows just completed — let a ONE_TIME contract close on delivery. for (const row of rows) { + // Intercity rows just completed — let a ONE_TIME contract close on delivery. if (row.trade_direction === 'DOMESTIC') { this.events.emit('booking.completed', { bookingId: row.id }); } + // Same event the per-booking unloadBooking() path emits — WarehouseInventoryService + // listens for this to auto-create the warehouse_inventory row (import/intercity only, + // it filters EXPORT itself). The bulk SQL update above skipped this entirely, so + // bookings caught by this fallback never left "awaiting unload". + this.events.emit('booking.unloadedAtYard', { + bookingId: row.id, + tradeDirection: row.trade_direction, + }); } return rows.map((r) => r.id); }