shoc-frontend-new/src/domain/work-orders/utils/completion-doc-auto-complete.ts

26 lines
1,020 B
TypeScript
Raw Normal View History

import type { CompDocSaveStatus } from "@/domain/work-orders/types/completion-doc";
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
import {
getClosabilityGaps,
tableRowToClosabilityInput,
} from "@/domain/work-orders/utils/wo-closability";
/**
* SH-115 / SH-341: completion is manual with confirmation, except that generating the
* completion document completes the WO — but only when the SH-114 closability gate passes
* on the persisted row. Not-required (NN) and drafts never complete; Past Due rows must be
* rescheduled before any status change, so they are left for the dispatcher.
*/
export function shouldCompleteAfterCompletionDoc(
status: CompDocSaveStatus,
row: WorkOrderTableRow,
): boolean {
if (status !== "Yes" || row.docStatus !== "Yes") {
return false;
}
if (row.status === "Completed" || row.status === "Canceled" || row.isPastDue) {
return false;
}
return getClosabilityGaps(tableRowToClosabilityInput(row)).length === 0;
}