Skip to content

Commit

Permalink
Handle notification number special case (#3369)
Browse files Browse the repository at this point in the history
  • Loading branch information
providenz authored Jun 3, 2024
1 parent 145069c commit 3a72807
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ describe("mutation.markAsProcessed", () => {
expect(resultingForm.status).toBe("NO_TRACEABILITY");
});

it("should mark a form as NO_TRACEABILITY when user declares it and with non-french EU destination", async () => {
it("should mark a form as NO_TRACEABILITY when user declares it, next destination is not provided and notificationNumber is missing", async () => {
const { user, company } = await userWithCompanyFactory("ADMIN");
const form = await formFactory({
ownerId: user.id,
Expand All @@ -537,11 +537,9 @@ describe("mutation.markAsProcessed", () => {
processedAt: "2018-12-11T00:00:00.000Z",
noTraceability: true,
nextDestination: {
notificationNumber: "abc",
processingOperation: "D 1",
company: {
vatNumber: "IE9513674T"
}
processingOperation: "D 1"
// next destination is not provided
// notification number not provided
}
}
}
Expand Down Expand Up @@ -678,6 +676,7 @@ describe("mutation.markAsProcessed", () => {
nextDestination: {
processingOperation: "D 1",
company: null
// no notification number
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,11 @@ function ProcessedInfo({ form, close }: { form: TdForm; close: () => void }) {
*/
useEffect(() => {
if (isExtraEuropeanCompany) {
/**
* Hack the API requirement for "any" value in nextDestination.company.extraEuropeanId
* in order to require notificationNumber
* Soon notificationNumber will be required for intra-european companies too
*/
setFieldValue("nextDestination.company", initNextDestination.company);
setFieldValue("nextDestination.company.country", "");
setFieldValue(
"nextDestination.company.extraEuropeanId",
!extraEuropeanCompany
? "UNIDENTIFIED_EXTRA_EUROPEAN_COMPANY"
: extraEuropeanCompany
!extraEuropeanCompany ? "" : extraEuropeanCompany
);
} else {
setIsExtraEuropeanCompany(false);
Expand Down Expand Up @@ -116,14 +109,24 @@ function ProcessedInfo({ form, close }: { form: TdForm; close: () => void }) {
const showNotificationNumber =
isExtraEuropeanCompany || (!isFRCompany && noTraceability) || hasVatNumber;

// Le numéro de notif est obligatoire quand : (-avec ou sans rupture de traçabilité)
// Le numéro de notif est obligatoire quand:
// - le code de traitement est non final
// - que le déchet est DD, pop ou marqué comme dangereux
// - entreprise (destination ultérieure) hors ue
// - ou entreprise (destination ultérieure) UE non française
// Si sansrupture de traçabilité:
// - entreprise (destination ultérieure) non française
// Si avec rupture de traçabilité:
// - entreprise (destination ultérieure) UE non française renseignée (via TVA ou n° d'identifiant)

const hasNextDestinationCompany = !!(
nextDestination?.company?.extraEuropeanId ||
nextDestination?.company?.siret ||
nextDestination?.company?.vatNumber
);

const notificationNumberIsMandatory =
(nextDestination && isExtraEuropeanCompany && isDangerousOrPop) ||
(nextDestination && hasVatNumber && isDangerousOrPop);
isDangerousOrPop && nextDestination && noTraceability
? hasNextDestinationCompany
: isExtraEuropeanCompany || hasVatNumber;

const notificationNumberIsOptional = !notificationNumberIsMandatory;
// nextDestination + hasVatNumber + isDangerousOrPop
Expand Down Expand Up @@ -297,7 +300,6 @@ function ProcessedInfo({ form, close }: { form: TdForm; close: () => void }) {
name="nextDestination.notificationNumber"
className="td-input"
placeholder={notificationNumberPlaceHolder}
required={notificationNumberIsMandatory}
/>
</>
)}
Expand Down

0 comments on commit 3a72807

Please sign in to comment.