intercity fix

This commit is contained in:
Marshal
2026-07-31 10:26:17 +00:00
parent d07a2e239e
commit 74b7ee81fc
11 changed files with 679 additions and 49 deletions

View File

@@ -3322,6 +3322,22 @@ export class BookingBatchService implements OnModuleInit {
booking: Booking,
reason: "paid" | "gov",
): Promise<void> {
// Stamp the computed wagon need on the link. Several callers pass a booking
// loaded without cargo relations (ensurePaidBookingAllocated), and a NULL
// wagonsRequired makes every capacity/occupancy reader miscount this
// booking as 1 wagon — reload with the relations wagonsFor sizes from.
const wagonDims = await this.loadWagonDims();
const full =
booking.bookingContainers || booking.cargoType
? booking
: await this.dataSource.getRepository(Booking).findOne({
where: { id: booking.id },
relations: {
bookingContainers: { containerType: true },
cargoType: true,
},
});
const wagonsRequired = this.wagonsFor(full ?? booking, wagonDims);
await this.dataSource.transaction(async (manager) => {
const exists =
await this.trainScheduleBookingsRepository.existsForBooking(
@@ -3338,6 +3354,7 @@ export class BookingBatchService implements OnModuleInit {
status: reason === "paid" ? "PAID" : booking.status,
schedulingStatus: "SCHEDULED",
scheduledAt: new Date(),
wagonsRequired,
paymentDeadline: null,
selectedForBatchAt: null,
} as never);