From 09baccebf6845958eaea0ae93c60793f50023d1f Mon Sep 17 00:00:00 2001 From: GaelFerrand Date: Tue, 26 Nov 2024 15:11:46 +0100 Subject: [PATCH] feat: modified seal rule on destinationCap --- back/src/bsda/validation/rules.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/back/src/bsda/validation/rules.ts b/back/src/bsda/validation/rules.ts index ea32fdbd00..6af943cb31 100644 --- a/back/src/bsda/validation/rules.ts +++ b/back/src/bsda/validation/rules.ts @@ -142,6 +142,18 @@ const sealedFromEmissionExceptAddOrRemoveNextDestination: GetBsdaSignatureTypeFn return isEmitter ? "WORK" : "EMISSION"; }; +const sealedFromEmissionExceptIfWorker: GetBsdaSignatureTypeFn = ( + _, + context +) => { + // Si entreprise de travaux: on peut modifier jusqu'à l'étape de transport + // Sinon, scellé dès la signature émetteur + const persisted = context!.persisted; + const hasWorker = persisted?.workerCompanySiret; + + return hasWorker ? "TRANSPORT" : "EMISSION"; +}; + /** * Renvoie la signature émetteur s'il n'y a pas d'entreprise de travaux sur le BSDA. * Sinon, renvoie la signature de l'entreprise de travaux. @@ -434,7 +446,7 @@ export const bsdaEditionRules: BsdaEditionRules = { }, destinationCap: { readableFieldName: "le CAP du destinataire", - sealed: { from: sealedFromEmissionExceptAddOrRemoveNextDestination }, + sealed: { from: sealedFromEmissionExceptIfWorker }, required: { from: "EMISSION", when: bsda =>