-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Appendix2MultiSelect) : group packagings by volume and aggregate…
… identification numbers
- Loading branch information
1 parent
a23133a
commit 02feef9
Showing
7 changed files
with
210 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
front/src/form/bsdd/components/appendix/__tests__/helpers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import { totalPackagings } from "../helpers"; | ||
import { InitialForm, InitialFormFraction, Packagings } from "@td/codegen-ui"; | ||
|
||
describe("totalPackagings", () => { | ||
it("should group packagings by type, volume, and other", () => { | ||
const annexedForms: InitialFormFraction[] = [ | ||
{ | ||
form: { | ||
wasteDetails: { | ||
packagingInfos: [ | ||
{ | ||
type: Packagings.Fut, | ||
volume: 20, | ||
other: null, | ||
quantity: 2, | ||
identificationNumbers: ["A", "B"] | ||
}, | ||
{ | ||
type: Packagings.Fut, | ||
volume: 30, | ||
other: null, | ||
quantity: 1, | ||
identificationNumbers: ["C"] | ||
} | ||
] | ||
} | ||
} as InitialForm, | ||
quantity: 1 | ||
}, | ||
{ | ||
form: { | ||
wasteDetails: { | ||
packagingInfos: [ | ||
{ | ||
type: Packagings.Grv, | ||
volume: 30, | ||
other: null, | ||
quantity: 1, | ||
identificationNumbers: ["D"] | ||
}, | ||
{ | ||
type: Packagings.Fut, | ||
volume: 20, | ||
other: null, | ||
quantity: 3, | ||
identificationNumbers: ["E", "F", "G"] | ||
}, | ||
{ | ||
type: Packagings.Autre, | ||
volume: 20, | ||
other: "Boite carton", | ||
quantity: 1, | ||
identificationNumbers: ["H"] | ||
} | ||
] | ||
} | ||
} as InitialForm, | ||
quantity: 1 | ||
}, | ||
{ | ||
form: { | ||
wasteDetails: { | ||
packagingInfos: [ | ||
{ | ||
type: Packagings.Autre, | ||
volume: 20, | ||
other: "Boite carton", | ||
quantity: 1, | ||
identificationNumbers: ["I"] | ||
} | ||
] | ||
} | ||
} as InitialForm, | ||
quantity: 1 | ||
}, | ||
{ | ||
form: { | ||
wasteDetails: { | ||
packagingInfos: [ | ||
{ | ||
type: Packagings.Autre, | ||
volume: 20, | ||
other: "Boite métallique", | ||
quantity: 1, | ||
identificationNumbers: ["J"] | ||
} | ||
] | ||
} | ||
} as InitialForm, | ||
quantity: 1 | ||
} | ||
]; | ||
|
||
const result = totalPackagings(annexedForms); | ||
expect(result).toEqual([ | ||
{ | ||
type: "FUT", | ||
volume: 20, | ||
other: null, | ||
quantity: 5, | ||
identificationNumbers: ["A", "B", "E", "F", "G"] | ||
}, | ||
{ | ||
type: "FUT", | ||
volume: 30, | ||
other: null, | ||
quantity: 1, | ||
identificationNumbers: ["C"] | ||
}, | ||
{ | ||
type: "GRV", | ||
volume: 30, | ||
other: null, | ||
quantity: 1, | ||
identificationNumbers: ["D"] | ||
}, | ||
{ | ||
type: "AUTRE", | ||
volume: 20, | ||
other: "Boite carton", | ||
quantity: 2, | ||
identificationNumbers: ["H", "I"] | ||
}, | ||
{ | ||
type: "AUTRE", | ||
volume: 20, | ||
other: "Boite métallique", | ||
quantity: 1, | ||
identificationNumbers: ["J"] | ||
} | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { InitialFormFraction, PackagingInfo } from "@td/codegen-ui"; | ||
|
||
// Permet de regrouper les conditionnements présents sur les annexes 2 par type, volume et other. | ||
// Exemple avec les annexes 2 et les conditionnements suivants : | ||
// - Première annexe : 2 fûts de 20L (n° A, B) et 1 fût de 30L (n° C) | ||
// - Deuxième annexe : 1 GRV de 30L (n°D) et 3 fûts de 20L (n°E, F, G) | ||
// On veut renvoyer 5 fûts de 20L (n°A, B, E, F, G), 1 fût de 30L (n°C) et 1 GRV de 30L (n°D) | ||
// avec les quantités et les numéros d'identifications qui ont été regroupés par type et par volume | ||
export function totalPackagings( | ||
annexedForms: InitialFormFraction[] | ||
): PackagingInfo[] { | ||
const packagingMap: { [key: string]: PackagingInfo } = {}; | ||
|
||
for (const { form, quantity } of annexedForms) { | ||
if (form.wasteDetails?.packagingInfos?.length && quantity) { | ||
for (const packagingInfo of form.wasteDetails.packagingInfos) { | ||
const { type, volume, other, quantity, identificationNumbers } = | ||
packagingInfo; | ||
|
||
const mapKey = `${type}-${volume ?? "0"}-${other ?? ""}`; | ||
|
||
const existingValue = packagingMap[mapKey]; | ||
|
||
if (existingValue) { | ||
packagingMap[mapKey].quantity += quantity; | ||
packagingMap[mapKey].identificationNumbers.push( | ||
...identificationNumbers | ||
); | ||
} else { | ||
packagingMap[mapKey] = { | ||
type, | ||
volume, | ||
other, | ||
quantity, | ||
identificationNumbers: [...identificationNumbers] | ||
}; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return Object.values(packagingMap); | ||
} |