mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-08 20:38:17 +00:00
implement self-healing for freight payment milestones and enhance contract change request visibility
This commit is contained in:
@@ -176,7 +176,28 @@ export class BookingClearanceService {
|
||||
}
|
||||
|
||||
const allApproved = await this.isClearanceFullyApproved(booking);
|
||||
const milestones = await this.workflowService.listMilestonesForBooking(bookingId);
|
||||
let milestones = await this.workflowService.listMilestonesForBooking(bookingId);
|
||||
|
||||
// Self-heal: a booking that has settled its freight payment must have
|
||||
// FREIGHT_PAYMENT_SETTLED completed. The batch settle path writes it, but an
|
||||
// export FCFS booking (linked to its train at booking time) paid via the
|
||||
// prepaid invoice can leave the milestone PENDING — the clearance "Payment &
|
||||
// wagon allocation" step then never ticks. Backfill it here so already-stuck
|
||||
// rows recover without a migration; idempotent (no-op once COMPLETED).
|
||||
const paymentSettled = milestones.find(
|
||||
(m) => m.milestoneCode === 'FREIGHT_PAYMENT_SETTLED',
|
||||
);
|
||||
if (
|
||||
paymentSettled &&
|
||||
paymentSettled.status === 'PENDING' &&
|
||||
(booking.paymentStatus === 'PAID' || booking.status === 'PAID')
|
||||
) {
|
||||
await this.workflowService.completeMilestoneForBooking(
|
||||
bookingId,
|
||||
'FREIGHT_PAYMENT_SETTLED',
|
||||
);
|
||||
milestones = await this.workflowService.listMilestonesForBooking(bookingId);
|
||||
}
|
||||
const phase = this.workflowService.resolvePhaseForBooking(booking, milestones);
|
||||
const nextAction = this.workflowService.computeNextActionForBooking(booking, milestones);
|
||||
const boundary = await this.workflowService.isBoundaryCompleteForBooking(
|
||||
|
||||
Reference in New Issue
Block a user