Skip to content

Commit

Permalink
Merge pull request #3620 from MTES-MCT/hotfix/tra-15172
Browse files Browse the repository at this point in the history
[TRA-15172] HOTFIX - Impossible de publier/modifier un BSFF de regroupement dont les BSFF initiaux ont un "Volume du contenant en L" à 0
  • Loading branch information
benoitguigal authored Sep 26, 2024
2 parents 8fabb38 + b1b1eb1 commit 2249b23
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
44 changes: 44 additions & 0 deletions back/src/bsffs/validation/bsff/__tests__/validation.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,50 @@ describe("validation > parseBsff", () => {
}
);

it.each([null, undefined])(
"should parse correctly if packaging volume is %p" +
" and bsff is created after MEP 2024.09.1 (in case of reexpedition)",
v => {
const zodBsff: ZodBsff = {
type: "REEXPEDITION",
isDraft: false,
createdAt: new Date("2024-09-24T08:00:00"),
packagings: [
{
weight: 1,
volume: v,
numero: "1",
emissionNumero: "1",
type: "BOUTEILLE"
}
]
};
expect(parseBsff(zodBsff)).toBeDefined();
}
);

it.each([null, undefined])(
"should parse correctly if packaging volume is %p" +
" and bsff is created after MEP 2024.09.1 (in case of groupement)",
v => {
const zodBsff: ZodBsff = {
type: "GROUPEMENT",
isDraft: false,
createdAt: new Date("2024-09-24T08:00:00"),
packagings: [
{
weight: 1,
volume: v,
numero: "1",
emissionNumero: "1",
type: "BOUTEILLE"
}
]
};
expect(parseBsff(zodBsff)).toBeDefined();
}
);

it("should throw if weight value is negative", () => {
const zodBsff: ZodBsff = {
weightValue: -1
Expand Down
6 changes: 5 additions & 1 deletion back/src/bsffs/validation/bsff/refinements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ export const checkPackagings: Refinement<ParsedZodBsff> = (
if (
(packaging.volume === null || packaging.volume === undefined) &&
!bsff.isDraft &&
![BsffType.REEXPEDITION, BsffType.GROUPEMENT].includes(bsff.type) &&
isCreatedAfterV2024091
) {
// TRA-14567 Le volume est rendu obligatoire sur les contenants BSFF
// à partir de la v2024091
// à partir de la v2024091. L'obligation ne concerne pas les bordereaux
// de groupement ou réexpedition pour ne pas bloquer des utilisateurs
// regroupant des BSFF crées avant 2024091 ayant un volume null (les contenants
// étant calculés automatiquement à partir des contenants réexpédiés / regroupés).
addIssue({
code: z.ZodIssueCode.custom,
message: "Conditionnements : le volume est requis"
Expand Down
10 changes: 1 addition & 9 deletions front/src/form/bsff/components/packagings/Packagings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ export default function BsffPackagings({
{value.map((p, idx) => {
const fieldName = `${name}.${idx}`;

const volumeIsDisabled =
disabled ||
([BsffType.Reexpedition, BsffType.Groupement].includes(type) &&
// Cas spécial pour le volume qui est rendu obligatoire à partir de la
// 2024.09.1 : on permet d'éditer le volume sur un bordereau de groupement ou réexpédition
// qui aurait un bordereau initial dont le packaging a un volume `null` ou `undefined`.
!!p.volume);

return (
<div
key={idx}
Expand Down Expand Up @@ -114,7 +106,7 @@ export default function BsffPackagings({
component={NumberInput}
className="td-input td-input--small"
name={`${fieldName}.volume`}
disabled={volumeIsDisabled}
disabled={fieldIsDisabled}
/>
</label>
</div>
Expand Down

0 comments on commit 2249b23

Please sign in to comment.